I wanted a PHP script to echo an XML-formatted results of a query to a MySQL database table. The script crashed/stopped when i had german umlaut or special character like ä,ö,ü,ß in a text column in the database
How-I-fixed-it:
There where a couple of steps required for me to make the special characters come through to the client browser.
1. Set the collation of the database table and the char columns to charset "utf8_general_ci"
2. In the PHP-code, force the DOMDocument to be UTF-8: $dom = new DOMDocument("1.0","UTF-8");
3. Set the database queries to be UTF-8: $names=mysql_query('set names utf8');
4. Set the charset of the mysql_connection to be UTF-8: mysqli_set_charset($connection, 'utf8');
5. Tell the client browser that the data is UTF-8 encoded: header('Content-Type: text/xml; charset=utf-8');
Maybe not all steps are really necessary, but once it worked for me, i left it that way :-)
I found some help here:
http://www.winfuture-forum.de/index.php?showtopic=193063
http://php.net/manual/de/domdocument.savexml.php
http://www.mysqltutorial.org/mysql-collation/
No comments:
Post a Comment