Home >Backend Development >PHP Tutorial >PHP writes data to CSV file sample code

PHP writes data to CSV file sample code

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:44:171352browse

php写入数据到CSV文件范例代码

  1. $row = 0;
  2. ini_set('max_execution_time', 300);
  3. $cate;$item;$value;$us;
  4. $fp = fopen("torah1.csv", "w");
  5. if (($handle = fopen("t.csv", "r")) !== FALSE) {
  6. while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  7. $num = count($data);
  8. $row++;
  9. for ($c=0; $c if($c==0){
  10. $us = $data[$c];
  11. }
  12. if($c==1){
  13. $item = explode(" ",$data[$c]);
  14. echo "
    ";
  15. print_r($item);
  16. } elseif($c==2){
  17. $value=$data[$c];
  18. }
  19. elseif($c==3){
  20. $cate1 = $data[$c];
  21. }
  22. else{
  23. }
  24. } // end of for loop
  25. if($row > 1838)
  26. {
  27. exit;
  28. }
  29. fputcsv($fp, array($us,$item[0],$item[1],$item[2],$item[3]));
  30. }//End of While
  31. }// End of IF
  32. fclose($handle);
  33. fclose($fp);
  34. ?>
复制代码

php, CSV


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn