note 22273 added to function.fgetcsv
| From: | joeldegan-AT-yahoo.com@php.net | Date: | Wed, 12 Jun 2002 17:01:23 +0000 |
| Subject: | note 22273 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31750@lists.php.net to get a copy of this message | ||
// function to parse multi arrays into csv data
// array in... array of array(datasets); first dataset = field names.
// usage:
/*
$toparse[0][0] = "field1";
$toparse[0][1] = "field2";
$toparse[1][0] = "value1";
$toparse[1][1] = "123123123"; // to see
echo export_to_csv($toparse);
*/
function export_to_csv($inarray){
while (list ($key1, $val1) = each ($inarray)) {
while (list ($key, $val) = each ($val1)) {
if (is_numeric($val)){
$sendback .= $val.",";
}else{
$sendback .= "\"". $val ."\",";
}//fi
}//wend
$sendback = substr($sendback, 0, -1); //chop last ,
$sendback .= "\n";
}//wend
return ($sendback);
}// end function
// send the file to the client.. pretty simple.
//usage:send_file_to_client("data.csv",export_to_csv($data));
function send_file_to_client($filename, $data){
header("Content-type: application/ofx");
header("Content-Disposition: attachment; filename=$filename");
echo $data;
};
--
http://www.php.net/manual/en/function.fgetcsv.php
http://master.php.net/manage/user-notes.php?action=edit+22273
http://master.php.net/manage/user-notes.php?action=delete+22273
http://master.php.net/manage/user-notes.php?action=reject+22273