Home >Backend Development >PHP Tutorial >PHP处理excel cvs表格的方法实例介绍_PHP
<?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 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>