Converting From Named to Numbered Entities

The Web is ever changing, and this article is relatively ancient having been published 7 years ago. It is likely out of date or even blatantly incorrect in relation to modern better practices, so proceed at your own risk.

I’ve been having some feed issues lately, thanks to my propensity for using proper(ish) typography, such as real quotes (“=“,”=”,‘=‘’=’) in my content and headlines. The problem was that XML doesn’t behave very well with some of the named HTML entities. My feed-generation code had some conversion set up using html_decode_entities() and a declared charset of UTF-8 for the document and decoded entities, which can handle them all, but for whatever reason no luck; It was still generating invalid RSS feeds. Matt Robinson’s code for conversion to numbered entities fixed it all up nice and clean-like. Thanks, man.