Fputcsv command to write csv files. Command: fputcsv () command format: intfputcsv (resourcehandle [, arrayfields [, stringdelimiter [, stringenclosure]) command parsing: fputcsv () transfers a line (using the fields array)
Command:Fputcsv ()
Command format:IntFputcsv(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, it returnsFALSE. 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:".
Write code (Error code):
$ 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), run the command to open it, 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.
Syntax fputcsv () command format: int fputcsv (resource handle [, array fields [, string delimiter [, string enclosure]) command parsing: fputcsv () upload a row (using the fields array...