简体   繁体   中英

Generate JSON file with PHP

I have PHP generating JSON data but I am having a problem making a example.json file from it. What am I doing wrong? I just get a blank screen.

<?php 
require('wp-load.php');

$EM_Events = EM_Events::get( array(
'scope'=>'future', 
'orderby'=>'event_start_date,event_start_time', 
'limit'=>1, 
'owner'=>false, 
'category'=>'6,7,8,10,11,12,13,14')
);

foreach ($EM_Events as $event) {
        //Event Detail
        $event_id = esc_html($event->event_id);
        $event_name = esc_html($event->name);


$events[] = array(
'event_id'=> $event_id,
'event_name'=> $event_name,
);

} 

$response['events'] = $events;

$fp = fopen('example.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);

?>

尝试使用诸如Fiddler http://www.fiddler2.com/之类的响应嗅探工具,或使用诸如Firebug http://getfirebug.com/之类的浏览器开发人员工具的“网络”选项卡,也许内容就可以了,仅仅是因为您的浏览器不知道如何呈现它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM