rocky_88 Posted January 18, 2012 Share Posted January 18, 2012 I'm using ajax to retrieve data from database. Using php when I echo the data, spanish characters such as "á é" are replaced by "�". After searching for hours I found out that this happens due to different charset. Using php utf8_encode() solves the problem and all characters are displayed properly. Out of curiosity I used mb_detect_encoding() to check the encoding and it shows that the encoding is UTF8. So if the encoding is UTF8 by default, then why dont I get proper output without the use of utf8_encode function? Quote Link to comment https://forums.phpfreaks.com/topic/255310-problems-with-encode/ Share on other sites More sharing options...
scootstah Posted January 18, 2012 Share Posted January 18, 2012 Is the encoding of the page in UTF8? Make sure this is in the HTML head: <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> Quote Link to comment https://forums.phpfreaks.com/topic/255310-problems-with-encode/#findComment-1308992 Share on other sites More sharing options...
rocky_88 Posted January 18, 2012 Author Share Posted January 18, 2012 @scootstah Thank you for the quick response, Yes, I do have that in HTML head, but still it does not seem to work unless I use utf8_encode function. Quote Link to comment https://forums.phpfreaks.com/topic/255310-problems-with-encode/#findComment-1308994 Share on other sites More sharing options...
scootstah Posted January 18, 2012 Share Posted January 18, 2012 That is indeed odd. If the encoding is already UTF8 that function shouldn't do anything. Quote Link to comment https://forums.phpfreaks.com/topic/255310-problems-with-encode/#findComment-1308999 Share on other sites More sharing options...
rocky_88 Posted January 18, 2012 Author Share Posted January 18, 2012 Ya, this problem never occurs when I use php. It happens only when I try to get data using ajax. Quote Link to comment https://forums.phpfreaks.com/topic/255310-problems-with-encode/#findComment-1309002 Share on other sites More sharing options...
scootstah Posted January 18, 2012 Share Posted January 18, 2012 What is the charset of the database? Quote Link to comment https://forums.phpfreaks.com/topic/255310-problems-with-encode/#findComment-1309004 Share on other sites More sharing options...
rocky_88 Posted January 18, 2012 Author Share Posted January 18, 2012 Charset of database is also UTF-8 Quote Link to comment https://forums.phpfreaks.com/topic/255310-problems-with-encode/#findComment-1309006 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.