How do I add encoding to DOM XML in PHP4?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nadavvin
Forum Commoner
Posts: 68
Joined: Wed Sep 06, 2006 6:05 am

How do I add encoding to DOM XML in PHP4?

Post by nadavvin »

The method "domxml_new_doc" get only one parameter of the xml version.

How do I set the encoding?
http://www.php.net/manual/en/function.d ... ew-doc.php
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

from a comment in the manual: libxml uses "UTF-8" internal encoding

Use mb_convert_encoding() on your node contents to make them UTF-8 as well

(I read somewhere that mb_convert_encoding() is faster than utf8_encode()...)
nadavvin
Forum Commoner
Posts: 68
Joined: Wed Sep 06, 2006 6:05 am

Post by nadavvin »

I want UTF-8 is not the problem.

But I also want that it will add in the XML output:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

two suggestions (ordered by wackiness)

1. pass the encoding as a second argument and see if it works

2. when all's said and done, do a preg_replace() on the document to add the text
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

When encoding="UTF-8" isn't present in <?xml UTF-8 encoding is assumed anyway.
Post Reply