PHP fputcsv Command Write CSV file encountered small problem (multidimensional array connector) _php tips

Source: Internet
Author: User
Command: Fputcsv ()
Command format: int fputcsv (resource handle [, array fields [, String delimiter [, String enclosure]]]
Command resolution: Fputcsv () formats a row (passed in fields array) in CSV format and writes to the file specified by handle. Returns the length of the write string, or FALSE if an error occurs. Optional delimiter parameter set field delimiter (only one character is allowed). The default is comma:,. Optional Enclosure parameter Set field field wrap character (only one character allowed). The default is double quotes: ".
Write code (error code):
Copy Code code as follows:

<?php
$users = Array (
Array ("User name", "department", "title");
Array ("User1", "1", "Secretariat", "clerk");
Array ("User2", "2", "Office", "clerk");
Array ("User3", "3", "Logistics Office", "clerk");
);
$handle = fopen ("Html/csvfile.csv", "w");
foreach ($users as $line) {
Fputcsv ($user, $line);
}
Put the file "please", but remember to "send it back."
Fclose ($handle);
?>

Code resolution: Create a new empty Csvfile.csv file (set manually) in the html/file directory, and then open it with a command, and write the files for the users array.
Error indications:

See this must surely know what wrong. “;” Is the culprit, beginnings Dawu Ah, the original multidimensional array of the connector is "," Ah, the wrong number of components, this error is very covert, do not suffer!
Remember: A multidimensional array of links using the "," (comma) Link

PHP fputcsv () function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.