CSV Export/Import Functions in PHP
Wednesday, September 19th, 2007
Functions to Export and import CSV data using PHP
//*Get the result of the query as a CSV stream.
function CSVExport($query) {
global $sql;
$sql_csv = $sql->getSqlHandle($query);
header("Content-type:text/octect-stream");
header("Content-Disposition:attachment;filename=data.csv");
while($row = mysql_fetch_row($sql_csv)) {
$row = $sql->_stripsls($row);
print '"' . implode('","',$row) . "\"\n";
}
exit;
}
[tags]php,export,import,csv,function[/tags]