This gem of an error seems to happen to me a lot. I always forget how to fix it and have to go on a scavenger hunt to find it.
SimpleXMLElement::addChild(): unterminated entity reference
You probably have code that looks like this or similar:
$item->addChild('book', 'Jack & Jill');
php halts at this line and your sitting there going "WHYYY?!?"
Here's all you need to do:
$item->addChild('book'); $item->book = 'Jack & Jill';
Or if you need a more dynamic approach:
$item->addChild($node); $item->$node = $content;
That's odd. But why? Well there's a great explanation here. But the jist of it is that the first way assumes that your "&" or "<" or other HTML entity characters are already encoded from your database and do not need coding. The second way that works for us in this case, will escape the "&" or other HTML entity for you. That sounds really weird, and is apparently a flaw in the SimpleXML that PHP won't fix for various reasons!