Home > Backend Development > PHP Tutorial > How to write data to CSV file in php, _PHP tutorial

How to write data to CSV file in php, _PHP tutorial

WBOY
Release: 2016-07-13 10:03:41
Original
818 people have browsed it

How to write data to CSV files in php,

The example in this article describes how to write data to CSV files in php. Share it with everyone for your reference. The specific implementation method is as follows:

<&#63;php
$row = 0;
ini_set('max_execution_time', 300);
$cate;$item;$value;$us;
$fp = fopen("torah1.csv", "w");
if (($handle = fopen("t.csv", "r")) !== FALSE) {
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count($data);
    $row++;
    for ($c=0; $c < $num; $c++) {
      if($c==0){   
      $us = $data[$c];
      }
      if($c==1){
      $item = explode(" ",$data[$c]);
      echo "<prE>";
      print_r($item);
      } elseif($c==2){
       $value=$data[$c];
      }
      elseif($c==3){
       $cate1 = $data[$c];
      }
      else{
      }
    } // end of for loop
    if($row > 1838)
    {
      exit;
    }
    fputcsv($fp, array($us,$item[0],$item[1],$item[2],$item[3]));
  }//End of While
 }// End of IF
  fclose($handle);
  fclose($fp);
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/967744.htmlTechArticleHow to write data to CSV files in PHP. This article describes the method of writing data to CSV files in PHP. Share it with everyone for your reference. The specific implementation method is as follows: php$row = 0;ini_set...
Related labels:
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