This blog was setup as a result of too much programming, I realised that I was getting back to the same problems which I had solved a few years ago. I thought a blog that can serve to remind me of what I did when i ran into programming problems :) So yep. Hence the title programming trail.
Wednesday, April 30, 2014
Sunday, April 27, 2014
SimpleXML error - unterminated entity reference.
While repurposing a blog today into XML doc, ran into the usual ampersand error. Warning
: SimpleXMLElement::addChild(): unterminated entity reference.
The error is a result of addchild inside SimpleXML, which does not automatically escapes ampersand. The best way to fix this problem is to simply not use the addchild method but instead of going direct:
// change the following:
// $childnode = $xml->addChild( $key, $value, 'url' );
// into this:
$xml->addChild( $key );
$xml->$key = $value;
Weird characters in PHP crawler/curl such as รข€™s...
Solution is to convert the doctype to UTF with the following line of code at the header:
header('Content-Type: text/html; charset=utf-8');

