Working with Language Characters in Mysql
wonder if anyone can help - I thought I had solved this but i still have some problems.
Basically people are inputting information into a CMS system I have inherited, from varying countries.
After a bit of help and research I have got it at开发者_JAVA技巧 least saving into the DB correctly. eg ó saves as ó.
However when retrieved from the DB it still says ó. Is there a way I can convert this to the ó on the php page, why would this not show correctly ?
I used mysql_set_charset('utf8',$link2); and set names in the setup file just after the connection, and the php pages in question seem to have to the correct meta of utf8, the pages are set to transistional in the header.
I have worked out by using the mb detect encoding that the php page is displaying the character in ascii.
Any thoughts appreciated.
Thanks
If your column's charset is utf-8, use the BINARY keyword when SELECTing:
SELECT BINARY utf8_column, ...
This will guarantee that the utf-8 data will not get converted in the way to the browser because PHP itself is encoding unaware and treats strings as stream of bytes.
And this is the custom function I use instead of htmlentities
that works well with utf-8 data:
function xmlEntities( $s ) {
return str_replace( array( '&', '"', '<', '>' ),
array( '&', '"', '<', '>' ), $s );
}
精彩评论