Sunday 5 May 2013

DOMdocument and the Pound Sign (£)

There's something odd about the way that PHP's DOMdocument function behaves if your HTML includes a pound sign, ie alt-0163 (which is pretty likely if you live here in the UK, where it is the currency symbol).

Attempts at replacing the symbol got me nowhere - echoing the file, it appeared to be coded as Â£, but str_replace using this string didn't do anything.

Eventually, I forensically examined the output character by character, and discovered that I needed to do a replace on
£

and from then on, everything was easy!