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