Problem with accent in DOMDocument between different php versions

I have an old large application in php that uses XML (DOMDocument).
The application runs on PHP 5.2.5

$dom = new DOMDocument("1.0", "iso-8859-15"); $dom->formatOutput = true; ... $node->setAttribute('attr', 'value_with_รฉร รจ'); $str = $dom->saveXML(); 

$ str is sent to Flex, and everything works fine.

Now we need to change our server. The new version of PHP is 5.2.13.
In this version, the setAttribute function does not work. (The line is not utf-8 .....)
And if I look at $ str, the line is cut at the first accent.

The code works if I use utf8_encode for attributes. The problem is that it takes a long time to parse the code and add utf8_encode .....
I am looking for a variable, flag or something else to make the application work like the old version of php.

Is there a trick?

+4
source share
1 answer

Was there. I feel your pain. Caracter coding problems are a pain in itself. Add MySQL, php and a web server to the mix and you will have serious problems.

First, you can configure the toolbox to use IS0-8859-15.

You have to make sure that you use any tool, php, mysql server, mysql-client (configurable via my.conf or php), and the web server is configured for this character set. You should also make sure that the DB tables are ISO-8859-15, do not transfer or open data in anything not configured for ISO-8859-15, for example ... (cough cough phpMyAdmin.)

I once had problems because I opened the db dump in my UTF8 editor before loading it into the ISO-8859-1 database, and just opening it in the editor and reloading it, it messed up the file with UTF8 conversion. Of course, these problems make you want to hit your head on the wall, but believe me, follow the instructions above, find a tool that uses UTF-8, starting from the database and from there, and you can serve these special characters without changing your code.

Good luck friend.

0
source

All Articles