I'm having trouble with writing special charcaters to a text file. The characters are your run-of-the-mill accented characters. Passing them back and forth in the database and displaying them on screen is NOT a problem.
code snippet:
$row = mysql_fetch_array($query_result, MYSQL_ASSOC);
foreach ($exportOrder as $key => $value) { // makes tab-delimited file from array
if (array_key_exists($key, $row)) {
$bigString .= $row[$key] . "\t";
} else {
$bigString .= "\t";
}
}
print $bigString;
$filename = "../../../Volumes/FILEJOB/DB Art IN/" . $row['currentSVVersion'];
if (!$file = fopen($filename, 'w+')) {
print "Cannot open file ($filename)";
exit;
}
fwrite($file, $bigString);
fclose($file);
I print the string immediately before I write the file. It looks like this (i hope this formats correctly for the list):
INGRÉDIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, ÉPICES À Â Æ Ç È É Ê Ë Î Ï Ô Û Ü Œ
I write the file, open it up in BBEdit (or your favorite text editor) and it looks like this:
INGR…DIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, …PICES ¿ ¬ ? « » … À †Œ œ ‘ € ‹ å
Why would I lose those special characters when writing to a text file? How can I avoid this? The text file will be opened offline, so using É and other character entities won't work.
I've tried:
- $file = fopen($filename, 'w+b'); adding binary flag doesn't affect anything
- Iooking at php.ini; nothing stood out
Any suggestions? [Mac OSX 10.3.6 : PHP 4.3.2 : MySQL 4.0.18 : Apache 1.3.29]
You are not loosing them, only bbedit does not display them in the original charset. Look in the bbedit menu or configuration if you can find some character encoding setting
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php