fputcsv command, small problems encountered when writing csv files_PHP tutorial

WBOY
Release: 2016-07-13 17:43:40
Original
878 people have browsed it

Command: fputcsv()

Command format: int fputcsv ( resource handle [, array fields [, string delimiter [ , string enclosure]]] )

Command parsing: fputcsv() formats a row (passed in the fields array) into CSV format and writes it to the file specified by handle. Returns the length of the written string. If an error occurs, FALSE is returned. The optional delimiter parameter sets the field delimiter (only one character is allowed). The default is comma: ,. The optional enclosure parameter sets the field wrapper (only one character allowed). The default is double quotes: ".

Writing code (Error code):

$users = array(

array("username", "department", "title");

array("user1","1","Secretariat","Officer");

array("user2","2","office","staff");

array("user3","3","Logistics Office","Secretary");

);

$handle = fopen("html/csvfile.csv","w");

foreach($users as $line){

fputcsv($user,$line);

}

//When you "invite" the documents to the elderly, remember to "send them back"

fclose($handle);

?>

Code analysis: Create a new empty csvfile.csv file (manually created) in the html/file directory, and then use command opens it and writes the users array to the file.

Error symptoms:

fputcsv command, small problems encountered when writing csv files_PHP tutorial

Seeing this, everyone must know what is wrong. ";" is the culprit. I suddenly realize that the connector in the multi-dimensional array is ",". I mistakenly typed a semicolon. This mistake is very hidden. Don't make it again!
Remember: Multidimensional arrays are connected using "," (comma)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478826.htmlTechArticleCommand: fputcsv() Command format: int fputcsv ( resource handle [, array fields [, string delimiter [, string enclosure]]] ) Command analysis: fputcsv() will pass a line (passed in fields array...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!