Reputation: 1656
I have XML like below, and I want to read the value of name
using PHP XPATH. I can read value if it is between start and end tags, but how to read value if XML is like this?
<a name="john" id="100" />
Upvotes: 0
Views: 28
Reputation: 1328
You can use this to get the value of name:
$xml = new SimpleXMLElement('<a name="john" id="100" />');
$name = (string)$xml->xpath('/a/@name')[0];
echo $name; // Output: john
Upvotes: 1