As you can guess from the title, this is not a really a Yii based article.  Recently, I spent a few frustrating hours trying to get some data loaded through libXML using simplexml_load_string with various odd parsing errors like:

Entity: line 21: parser error : EntityRef: expecting ';' in 

It’s not UTF-8

As a European, I use UTF-8 all the time.  The database is UTF-8.  The Db connection is UTF-8.  My data is validated as UTF-8.  Do you follow?

But, and this is a big BUT …

libXML doesn’t always like it.

The Solution

As often, was really simple, to re-validate and pass everything through utf8_encode before passing it to simplexml_load_string or simplexml_load_file

$c=utf8_encode (file_get_contents($url));