<?PHP
include('config.php');
function cleanData(&$str)
{
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
}
// filename for download
$filename = "Piante_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$flag = false;
$result = mysql_query("SELECT * FROM photo where flag='active'") or die('Query failed!');
while(false !== ($row =mysql_fetch_assoc($result))) {
if(!$flag) {
// display field/column names as first row
echo implode("\t", array_keys($row)) . "\r\n";
$flag = true;
}
array_walk($row, 'cleanData');
echo implode("\t", array_values($row)) . "\r\n";
}
exit;
?>
Hy i'm using this code to export excell from the db, i'm having problem that when i open the file excell show me an error something like different format that specified by the file name open anyway?, its work anyway, next problem is that i whant to customize he collum name, i see that array_keys, but i'm not able to change it i've tryied to make only echo with \r\n with the name of columns but nothing...