Firstly, when I came across this problem recently, I solved it by making sure that my code files, database connection and database tables were all UTF-8. Then just the echo of the text works. If you should avoid database output, use htmlspecialchars() rather than htmlentities() so that UTF-8 characters are left alone and not trying to escape.
I would like to document an alternative solution, because it solved a similar problem for me. I used PHP utf8_encode() to remove special characters.
I wanted to convert them to HTML objects for display, I wrote this code because I wanted to avoid iconv or such functions as much as possible, since not all environments necessarily have them (correct me if it is not!)
$foo = 'This is my test string \u03b50'; echo unicode2html($foo); function unicode2html($string) { return preg_replace('/\\\\u([0-9a-z]{4})/', '&#x$1;', $string); }
Hope this helps someone need this :-)
source share