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');
Subscribe to:
Posts (Atom)