Home > Article > Backend Development > How to write data to CSV file in php
This article mainly introduces the method of writing data to CSV files in PHP. It involves the skills of PHP operating CSV files. It is of great practical value. Friends in need can refer to it.
The example of this article tells the story of writing data in PHP. How to import data into a CSV file. The specific implementation method is as follows:
<?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); ?>
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.
Related recommendations:
The function of converting PHP array to Apple plist XML or text format
php realizes the collection of China proxy server network
php uses curl to connect to the website and obtain information
The above is the detailed content of How to write data to CSV file in php. For more information, please follow other related articles on the PHP Chinese website!