Steven
Steven

Reputation: 13975

Convert string for XML (UTF-8)

I have a string such as Hélène Lee, Christophe Farnarier (co) 2010 | The First Rasta | 86 min. and I need to convert it so I can print it in a XML node. Which is currently giving me an error XML Parsing Error: undefined entity at the é part.

Is there a way to convert it to the #275; or what ever it is numerical entry? Or another way to do this? It is not just é there are several other special characters as well.

Thanks

Upvotes: 0

Views: 437

Answers (2)

ajreal
ajreal

Reputation: 47311

there is no built-in PHP function that able to convert HTML entities into numeric entities that acceptable by XML

search for php numeric entities lead to here : http://www.lazycat.org/php-convert-entities.html , the conversion mentioned in the article should have covered most of the HTML entities

Upvotes: 1

Pekka
Pekka

Reputation: 449385

Use html_entity_decode() to decode the entities back into their original characters. There is no need to use entities here.

The third parameter specifies the encoding - it defaults to ISO-8859-1 before PHP 5.4, so be sure to specify UTF-8 explicitly.

Upvotes: 0

Related Questions