PHP: How to convert ISO character (HTMLEntities) to UTF-8?

I’m facing problem in how to convert string from ISO to UTF8 previously. Due to the server configuration problem, all the UTF-8 char has been convereted into ISO (HTMLEntities) before it insert into db and those ISO character (HTMLEntities) break while showing in XML document. Now i found the solution to convert ISO character into UTF-8.
The original utf-8 chinese words: “你好”.
Converted to ISO (HTMLEntities) : “你好”
For you to convert the ISO string “你好” to become utf-8 chinese words: “你好”, you need to use Multibyte String function (or mbstring extension). Example below uses mb_convert_encoding function to convert ISO (HTMLEntities) characters to UTF-8:-
$str = “你好”;
echo mb_convert_encoding($str, ‘UTF-8′, ‘HTML-ENTITIES’);
?>
Output will be 你好.
*** To find out if the conversion from ISO to utf-8 is working, you need to view source (view the html source code) to check if the character is in UTF-8 format. (do not trust what your browser shows you!) ***
This example need u to have mbstring extension installed. By default, mbstring extension is not installed. If you do not have mbstring installed you wont be able to convert the ISO string to UTF-8 using the method i show here. You may need to contact your server administrator to install mbstring extension.
Tags: convert htmlentities to utf8, convert iso to utf8, convert string to utf-8, convert string to utf8, php character encoding problem, php convert iso to utf8, php how to
Posted at June 28th, 2007 by chua
If you think this article helps you to solve your problem and clear your headache, feel free to buy me a drink :)



June 28th, 2007 at 8:06 am
thanks for sharing the tips.
previously, I also facing the same problem,
the end, copy and paste …….
June 28th, 2007 at 6:37 pm
if you have just few records then copy and paste is not the big problem, but if you want to convert a large number of record then you need to use this method to do a batch conversion
September 12th, 2008 at 6:33 pm
if we have a rss feed that is encoded in widows-1250 and our web site is encoded in UTF-8 ..how we can then make visible on the web site the data that we are retrieving from that feed ?
I dont want to change web site’s enoding..
help ?plz..
October 25th, 2008 at 11:04 am
[...] PHP: How to convert ISO character (HTMLEntities) to UTF-8? [...]