Using PHP variables that contain hyphens

David Nash php 2 Comments

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 <HELLO-THERE>.

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

Instead, use $xml->{“HELLO-THERE”}

Easy!

Comments 2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.