How to extract data from csv file in PHP

前端 未结 11 1462
醉酒成梦
醉酒成梦 2020-11-22 07:36

I have a csv file which looks like this

$lines[0] = \"text, with commas\", \"another text\", 123, \"text\",5;
$lines[1] = \"some without commas\", \"another          


        
11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 08:08

    here is also a simple method to get read csv file.

    $sfp = fopen('/path/to/source.csv','r'); 
    $dfp = fopen('/path/to/destination.csv','w'); 
    while ($row = fgetcsv($sfp,10000,",","")) { 
     $goodstuff = ""; 
     $goodstuff = str_replace("¦",",",$row[2]); 
     $goodstuff .= "\n"; 
     fwrite($dfp,$goodstuff); 
    } 
    fclose($sfp); 
    fclose($dfp);
    

提交回复
热议问题