Search code examples
phpsimplexmlutf8-decode

utf8_decode error with ampersand (&)


I have been building an API which returns XML code. For example, the API will return:

<message>hello, this is a message &amp; it used htmlsepcialchars</message>

I am using file_get_contents() and simplexml_load_string() to load the returned information into an array.

I then used utf8_decode() to convert the message into a friendly charset on the receiving website. However, I receive the following message which pin points to the ampersand (&) in the message:

Warning: main() [function.main]: unterminated entity reference 

Due to the ampersand, the rest of the message is truncated. Any ideas how to get around this problem?


Solution

  • Found my answer, user error. I was basically escaping again somewhere in my code.