XML tag with hyphens


This took me a little while to work out. I’m using PHP5’s SimpleXML to parse XML into a PHP object. The XML has entries like <first-name>.

But you can’t use $xml->first-name because it reads the hyphen as a minus.

Instead, use $xml->{‘first-name’}

Cheers!

Advertisements
Posted in PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s