fwrite() seems to destroy Special Characters

From: Date: Wed, 17 Nov 2004 22:26:20 +0000
Subject: fwrite() seems to destroy Special Characters
Groups: php.general 
Request: Send a blank email to php-general+get-202347@lists.php.net to get a copy of this message
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] D

« previous php.general (#202347) next »