likes
comments
collection
share

PHP 读取 xxx.json 文件, 并将内容以 table 表格形式输出到浏览器

作者站长头像
站长
· 阅读数 29
echo '<table>
    <thead>
        <tr>
            <th width=200>id</th>
            <th width=200>name</th>
            <th width=200>is_new_page</th>
        </tr>
    </thead>
    <tbody>';
    
$file = array("./fb_pages_json/01.json", "./fb_pages_json/02.json", "./fb_pages_json/03.json");
//print_r($decode_data);
for($k=0; $k<3;$k++) {
    $json_data = file_get_contents($file[$k]);
    $decode_data = json_decode($json_data, true);
    for ($i=0; $i<count($decode_data['data']); $i++) {
        $id = $decode_data['data'][$i]['id'];
        $name = $decode_data['data'][$i]['name'];
        $is_new_page = $decode_data['data'][$i]['has_transitioned_to_new_page_experience'];
        if(! $is_new_page){
            $is_new_page = 'false';
        }else{
            $is_new_page = 'true';
        }
            echo '<tr><td>'.$id.'</td><td>'.$name.'</td><td>'.$is_new_page.'</td></tr>';
    }
}
echo '</tbody></table>';
转载自:https://segmentfault.com/a/1190000041599955
评论
请登录