I have a php script that creates a comma-delimited text file using database data. Some of the fields in the database will have information in them containing double-quotes. Here is an example of how I am building the file:
while ($fetched_ary = mysql_fetch_array($query_result))
{
$file_line = "\"" . $fetched_ary[field1] . "\",\"" . $fetched_ary[field2]. "\"\n";
fwrite($file_pointer, $file_line);
}
As a trick to make the file readible by Excell 2000, I change the file extension with the "rename" function to .csv from .txt:
$filename = "myfile.txt";
$csv_filename = "myfile.csv";
rename($filename, $csv_filename);
My script then makes a hyperlink on the screen to this file that they may use to get the file.
NOW, what ends up happening is that field2, for example, will containg data like:
Mystic Horizon - "An Oasis of Health & Wellness"
When this gets saved into the file though, it looks like:
Mystic Horizon - An Oasis of Health & Wellness""
What I would like to know is:
- Is there a way that I can build a file string without loosing the position of these double-quotes? Or is this something Excel is doing that is fudging the data?
I have magic_quotes_gpc ON, but not magic_quotes_runtime or _sybase.