You are here: How do you read/write UTF-8-encoded XML scripts using PHP? « PHP Programming Language « IT news, forums, messages
How do you read/write UTF-8-encoded XML scripts using PHP?

Posted by comp.lang.php on 09/27/98 11:37

I have a very simple XML file I created as a sample:

[Quote]
<?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>
[/Quote]

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):

[PHP]
$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);

[/PHP]

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:

[Quote]
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
[/Quote]

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация