PHP fputcsv command to write CSV file encountered minor problems (multidimensional array connector)

Source: Internet
Author: User
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) in CSV format and writes the file specified by handle. Returns the length of the write string, and FALSE if an error occurs. The optional delimiter parameter sets the field delimiter (only one character is allowed). The default is comma:,. The optional Enclosure parameter sets the Field field wrapping character (only one characters allowed). The default is double quotation marks: ".
Write code (error code):

Copy the Code code as follows:


$users = Array (
Array ("User name", "department", "title");
Array ("User1", "1", "Secretariat", "clerk");
Array ("User2", "2", "Office", "clerk");
Array ("User3", "3", "Logistic Office", "clerk");
);
$handle = fopen ("Html/csvfile.csv", "w");
foreach ($users as $line) {
Fputcsv ($user, $line);
}
"Please come" and remember to "send it back".
Fclose ($handle);
?>


Code parsing: Create a new empty Csvfile.csv file (created manually) under the html/file directory, open it with a command, and write a file of the users array.
Error indications:

See this presumably everyone knows what's wrong. “;” Is the culprit, Huanran Dawu Ah, the original multi-dimensional array of the linker is "," ah, mistakenly hit ingredient number, this error is very hidden, do not suffer!
Remember: the links of multidimensional arrays use "," (comma) linked
PHP fputcsv () function

The above describes the PHP fputcsv command to write a CSV file encountered small problems (multidimensional array connector), including the aspects of the content, you want to be interested in PHP tutorial friends helpful.

  • 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.