Home >Backend Development >PHP Tutorial >Example introduction to the method of processing excel cvs table with PHP_PHP tutorial
<?php <BR>$data = array(); <BR>//convert a cvs file to an array $data <BR>$handle = fopen("data.csv","r"); <BR>while ($curline = fgetcsv($handle, 1000, ",")){ <BR>$tmp = array(); <BR>$num = count($curline); <BR>for($c=0; $c < $num; $c++){ <BR>array_push($tmp, $curline[c]); <BR>} <BR>array_push($data, $tmp); <BR>} <BR>print_r($data); <BR>fclose($handle); <BR>//convert array $data back to a cvs file <BR>$handle = fopen("result.csv","w"); <BR>foreach($data as $curline){ <BR>if(fputcsv($handle, $curline)==false){ <BR>die("cannot write CSV line"); <BR>} <BR>} <BR>fclose($handle); <BR>?> <br>