Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using domdocuments and using things like $div->nodeValue to obtain certain info from a web page.

On my ubuntu machine when i do php crawl.php everything is displayed properly in Chinese (the page is in UTF-8).

However on my CENTOS machine using the same code I get æ´å¤åå¸ when I print in the terminal. and when I save it to the database, the characters are also messed up.

One thing I noticed is that when I do print $content, both systems display them properly.

share|improve this question

1 Answer 1

Check mysql connection charset & collation, while you insert the content of grabbed data, Mysql should know which charset & collation will be used to store data. add the lines below to your php script. by this way your code will be much more stable to work on different OS'es & configurations.

`
$dbcharset='utf8';
$dbcollation='utf8_general_ci';
mysql_query('SET CHARACTER SET '.$dbcharset); 
mysql_query("SET NAMES '".$dbcharset."' COLLATE '".$dbcollation."'");
`
share|improve this answer
    
mysql_query() should be sent after mysql_select_db(); & before any select or insert query. –  risyasin May 29 '10 at 9:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.