PHP writes data to CSV file sample code

WBOY
Release: 2016-07-25 08:44:17
Original
1252 people have browsed it

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 < $num; $c++) {
  10. if($c==0){
  11. $us = $data[$c];
  12. }
  13. if($c==1){
  14. $item = explode(" ",$data[$c]);
  15. echo "
    ";
  16. print_r($item);
  17. } elseif($c==2){
  18. $value=$data[$c];
  19. }
  20. elseif($c==3){
  21. $cate1 = $data[$c];
  22. }
  23. else{
  24. }
  25. } // end of for loop
  26. if($row > 1838)
  27. {
  28. exit;
  29. }
  30. fputcsv($fp, array($us,$item[0],$item[1],$item[2],$item[3]));
  31. }//End of While
  32. }// End of IF
  33. fclose($handle);
  34. fclose($fp);
  35. ?>
复制代码

php, CSV


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template