Getting data from XML node in php [duplicate]

iran2008

New Member
This question already has an answer here: I am retrieving an XML data from url and I want to extract data from the particular nodes. Here is my XML Data\[code\]<person> <first-name>ABC</first-name> <last-name>XYZ</last-name></person>\[/code\]Here's my PHP code:\[code\]$content = file_get_contents($url);$xml = simplexml_load_string($content);foreach($xml->children() as $child) { echo $child->getName() . ": " . $child->first-name . "<br>"; }\[/code\]PHP returns this error: \[code\]Use of undefined constant name - assumed 'name'\[/code\]So where am I going wrong?
 
Back
Top