PHP fputcsv command small problems encountered when writing csv files (multidimensional array connector)

WBOY
Release: 2016-07-29 08:45:15
Original
1199 people have browsed it

Command: fputcsv()
Command format: int fputcsv (resource handle [, array fields [, string delimiter [, string enclosure]]])
Command analysis: fputcsv() formats a row (passed in fields array) into CSV format and writes to the file specified by handle. Returns the length of the written string, or FALSE on error. 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):

Copy code The code is as follows:


$users = array(
array("Username","Department" ,"Professional title");
array("user1","1","Secretariat","Secretary");
array("user2","2","Office","Secretary");
array("user3","3","Logistics Department","Department Member");
);
$handle = fopen("html/csvfile.csv","w");
foreach($users as $ line){
fputcsv($user,$line);
}
//When you "invite" the file, remember to "send it back"
fclose($handle);
?>


Code analysis: Create an empty csvfile.csv file in the html/file directory (create it manually), then open it with the command and write the users array file.
Error symptoms:
 php fputcsv命令 写csv文件遇到的小问题(多维数组连接符)
You must know what is wrong when you see this. "" "," (comma) linked
PHP fputcsv() function
The above has introduced the minor problems encountered when writing csv files using the php fputcsv command (multidimensional array connectors), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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