Command: fputcsv()
Command format: int fputcsv (resource handle [, array fields [, string delimiter [, string enclosure]]])
Command analysis: fputcsv() formats a row (passed in fields array) into CSV format and writes to the file specified by handle. Returns the length of the written string, or FALSE on error. The optional delimiter parameter sets the field delimiter (only one character is allowed). The default is comma:,. The optional enclosure parameter sets the field wrapper (only one character allowed). The default is double quotes: ".
Writing code (error code):
Copy code The code is as follows:
$users = array(
array("Username","Department" ,"Professional title");
array("user1","1","Secretariat","Secretary");
array("user2","2","Office","Secretary");
array("user3","3","Logistics Department","Department Member");
);
$handle = fopen("html/csvfile.csv","w");
foreach($users as $ line){
fputcsv($user,$line);
}
//When you "invite" the file, remember to "send it back"
fclose($handle);
?>