I've an old big application in php that uses XML (DOMDocument).
The application works on PHP 5.2.5$dom = new DOMDocument("1.0", "iso-8859-15");
$dom->formatOutput = true;
...
$node->setAttribute('attr', 'value_with_éàè');
$str = $dom->saveXML();
开发者_如何学Python$str is sent to Flex and everything works fine.
Now, we have to change our server. The new version of PHP is 5.2.13.
In this version, the function setAttribute fails. (String is not utf-8.....) And If I look $str, the string is cut at the first accent.The code works if I use utf8_encode for attributes. The problem is that will take a lot of time to parse the code and add utf8_encode.....
I'm looking for a variable, a flag or something else to keep the application working like the old version of php.Is there a trick ?
Been there. I feel your pain. Caracter encoding issues are a pain in themselves. Add MySQL, php and a webserver to the mix and you have some heavy-duty issues to work out.
First off, it is possible to configure your toolset to use IS0-8859-15.
You have to make sure EVERY tool you use, php, mysql server, mysql-client ( configurable through my.conf or in php) , and webserver are configured for this caracter set. You also have to make sure the DB tables are ISO-8859-15, do not transfer with or open the data in anything not configured for ISO-8859-15 like...(cough cough phpMyAdmin.)
I once had problems because I opened the db dump in my UTF8 editor before loading it in ISO-8859-1 DB, and just opening in the editor and resaving it corrupted the file with UTF8 conversion. Of course these issues make you want to bang your head on a wall but trust me, follow the steps above, find the tool that uses UTF-8 start at DB and go from there and you shall be able to serve those special caracters without changing your code.
Good luck friend.
精彩评论