Using PHP variables that contain 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 <HELLO-THERE>.

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

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

Easy!

Share:
  • del.icio.us
  • Facebook
  • Google
  • E-mail this story to a friend!
  • Technorati
  • TwitThis

Leave a Reply