Want to generate .json file with PHP? Use the below PHP program to generate .json file using PHP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php $sql="select * from Posts limit 20"; $response = array(); $posts = array(); $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $title=$row['title']; $url=$row['url']; $posts[] = array('title'=> $title, 'url'=> $url); } $response['posts'] = $posts; $fp = fopen('results.json', 'w'); fwrite($fp, json_encode($response)); fclose($fp); ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.