I have a very simple XML file I created as a sample:
<?xml version="1.0" encoding="UTF-8" ?>
<stuff>
<blah id="1">Om du vet hur många gånger blivit jag trevligt överkritisk på jättekult bajset!</blah>
</stuff>
I am trying to simply read it using tree-based XML functions in PHP which I know (sorry, don't know or quickly understand DOM though that might be a better option if someone wants to tutor me in it):
$fileID = @fopen($_SERVER['DOCUMENT_ROOT'] . '/stuff.xml', 'rb'); // THIS WORKS
$contents = @fread($fileID, filesize($_SERVER['DOCUMENT_ROOT'] . '/stuff.xml')); // $contents HAS THE ENTIRE XML CONTENTS
@fclose($fileID); // NO PROB
$parser = xml_parser_create(); // WORKS JUST FINE
xml_parse_into_struct($parser, $contents, $xmlArray, $tags); // $xmlArray and $tags are both empty arrays! But why?
xml_parser_free($parser);
This seems to happen with PHP versions 4.1.2 - 5.0.4 with me trying to work with a UTF-8 encoded XML script created in the following manner:
1. Using Windows XP Notepad, wrote script
2. Saved as "stuff.xml" using UTF-8 encoding as I'm saving it
3. Verified well-formed XML by opening in both Firefox and IE
Is there something missing or just not right here, or the worst-case scenario: PHP can't read UTF-8-encoded XML in at least tree form?
This affects one particular site that has no access to a DB that utilizes simple data in XML format, however, the data may contain foreign characters.
Thanx
Phil