Answers for "csv to json php"

PHP
0

csv to json php

<?php
 
//Open our CSV file using the fopen function.
$fh = fopen("names.csv", "r");
 
//Setup a PHP array to hold our CSV rows.
$csvData = array();
 
//Loop through the rows in our CSV file and add them to
//the PHP array that we created above.
while (($row = fgetcsv($fh, 0, ",")) !== FALSE) {
    $csvData[] = $row;
}
 
//Finally, encode our array into a JSON string format so that we can print it out.
echo json_encode($csvData);
Posted by: Guest on June-20-2020

Browse Popular Code Answers by Language