Phpfputcsv command to write csv file small problem (multi-dimensional array connector) _ PHP Tutorial

Source: Internet
Author: User
Small issues encountered when writing csv files using the phpfputcsv command (multi-dimensional array connector ). Command: fputcsv () command format: intfputcsv (resourcehandle [, arrayfields [, stringdelimiter [, stringenclosure]) command parsing: fputcsv () transfers a line (using fields array command: fputcsv ()
Command format: int fputcsv (resource handle [, array fields [, string delimiter [, string enclosure])
Command parsing: fputcsv () format a row (transmitted using the fields array) into CSV format and write 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 value is comma :,. The optional enclosure parameter sets the field surround character (only one character is allowed ). Double quotation marks by default :".
Compile the code (error code ):

The code is as follows:


$ Users = array (
Array ("user name", "department", "title ");
Array ("user1", "1", "Secretariat", "clerk ");
Array ("user2", "2", "office", "clerk ");
Array ("user3", "3", "logistics", "clerk ");
);
$ Handle = fopen ("html/csvfile.csv", "w ");
Foreach ($ users as $ line ){
Fputcsv ($ user, $ line );
}
// Please remember to send the document back when the old man "invites"
Fclose ($ handle );
?>


Code parsing: create an empty csvfile.csv file under the html/file directory (manually created), open it with commands, and write the files in the users array.
Error symptoms:

When you see this, you must know what went wrong. ";" Is the culprit. I was enlightened that the link character in the multi-dimensional array was "," and it was mistakenly typed into a semicolon. this error is concealed and should not be further affected!
Remember: use commas (,) to link multi-dimensional arrays.

PHP fputcsv () function

Syntax fputcsv () command format: int fputcsv (resource handle [, array fields [, string delimiter [, string enclosure]) command parsing: fputcsv () pass a row (using the fields array...

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.