I’m trying to write the json object into a CSV file, but it’s not working the file is empty.
any advice?
below my PHP code
//json to csv
$jsondata = '{"regNo":"92-212-98","tradName":"FEVADOL EXTRA TAB.","genericName":"PARACETAMOL, CAFFEINE","price":"5.300","strngth":"500, 65 mg","exD":"21/07","PRODREGSTATUS":"PRODNOTFOUND","authstatus":"1","marketingstatus":"1","productstatus":null}';
$json = json_decode($jsondata);
$fp = fopen('file.csv', 'w');
// if($fp == false){
// echo 'false open';
// }else{
// echo 'true open';
// }
foreach ($json as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);