Extract data from csv file using php script

Copy following code and past in your php file

$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        $row++;
        for ($c=0; $c < $num; $c++) {
print_r($data);
echo "<br>";
        }
    }
    fclose($handle);
}

There output will be:


Array ( [0] => City [1] => County )
Array ( [0] => City [1] => County )
Array ( [0] => Atlanta [1] => Fulton, DeKalb )
Array ( [0] => Atlanta [1] => Fulton, DeKalb )
Array ( [0] => Augusta [1] => Richmond )
Array ( [0] => Augusta [1] => Richmond )
Array ( [0] => Columbus [1] => Muscogee )

Comments

Popular posts from this blog

dynamic create multiple ckeditor onclick event using jquery

get lat and long from city name using jquery

membership registration and login system in php