I can’t seem to get anything to work with simpleXML for PHP. What is wrong with the following:
$xml = simplexml_load_string('<book><title>The Title</title></book>');
$title = $xml->book->title;
echo "<pre>title = $title\n</pre>";
The resulting output is:
title =
Why isn’t the output as follows?
title = The Title
Please advise.
Since
<book>is the root node of this snippet, you need$xml->titlerather than$xml->book->title.The structure is more easily discovered if you
var_dump()it: