Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Read the JSON file
- $json = file_get_contents('text.json');
- // Decode the JSON file
- $json_data = json_decode($json, true);
- // Display data
- // print_r($json_data);
- echo "firstName;lastName;gender;age;number\r\n";
- foreach ($json_data as $key) {
- echo $key["firstName"].";".$key["lastName"].";".$key["gender"].";".$key["age"].";".$key["number"]."\r\n";
- }
- // Open a file in write mode ('w')
- $fp = fopen('text.csv', 'w');
- // Loop through file pointer and a line
- foreach ($json_data as $key) {
- fputcsv($fp, $key, ";");
- }
- fclose($fp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement