tags:

views:

33

answers:

1

I am trying to extract some data from XML but when I execute the following I get a "Warning: Invalid argument supplied for foreach() in ..." message

foreach ($xml->custom-field-value as $milestone) {

  print "<tr>";

  print "<td>".$milestone->{'field-number'}." ".$milestone->{'value'}."</td>";

  print "</tr>";

}

It works fine for node names that are single words so I am guessing that it doesn't like the hyphens. Do I need to escape them and if so how?

+2  A: 

From PHP manual:

Accessing elements within an XML document that contain characters not permitted under PHP's naming convention (e.g. the hyphen) can be accomplished by encapsulating the element name within braces and the apostrophe.

In your case you do:

$xml->{'custom-field-value'}
codaddict
Perfect! Thanks.
williamsdb