Hi,
I'm writing a table data to a CSV file without problems.
BUT I'm having trouble to include field names in the CSV file.
The txt is perfectly written, but I can't open it with Excel.
When I try to open the file with Excel, it throws the following error: "SYLK: invalid file format".
So I've tried escaping fieldnames (assuming they are between double quotes or single quotes), but still doesn't work.
There must be a workaround because you can do this with PhpMyAdmin.
Here's my code:
$query=mysql_query("some query");
$i = 0;
while ($i < mysql_num_fields($query)) {
$meta = mysql_fetch_field($query);
if (!$meta) {
echo "No information available<br />\n";
}
$title="$meta->name;";
*/ I tried escaping all this characters inside the loop, but no luck
$title=str_replace(""","",$title);
$title=str_replace("'", "", $title);
$title=str_replace("'", "\'", $title);
$title=str_replace('"', '\"', $title );
*/
$write = fputs($handle, $title);
$i++;
}
fclose($handle);
Can somebody help me?
I've tried for hours....