Saving XML file w/ UTF-8
Posted on 2008-10-21
I'm trying to save an xml file formatted in UTF-8 but it doesn't appear to be working. Here is a condensed version of my code:
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
mysql query goes here...
$xml .= "mysql xml output";
$folder = $_SERVER['DOCUMENT_ROOT']."/path";
$tempfile = $folder."/".date("Ymd").".xml";
$fo = fopen($tempfile, 'w') or die("Cannot create XML file.");
For some reason, I open the file and the UTF-8 characters are not recognized (seen as question marks). In the MySQL db, the collation is set to utf8_unicode_ci. Is there a way to set the file encoding when I am opening the file or writing to it?