Just came across a bit of a time-waster in the PHP SimpleXMLElement lib.  Usually if you’re accessing an element called, say ‘username’ you use the follwoing syntax:

$username = $element->username;

However if the element has a minus sign in its name, like ‘user-name’ you have to use the following syntax instead:

$username = $element->{’user-name’};

If you use the original syntax no data will be returned, mad stuff, I would have wasted much more time on this if it wasn’t for this post - Thanks for the dig-out!


Related Posts


Leave a Reply