The XML I am reading looks like this:
The Big Bang Theory
http://www.tvrage.com/The_Bi
This should work.
$id = $xml["id"];
Your XML root becomes the root of the SimpleXML object; your code is calling a chid root by the name of 'show', which doesn't exist.
You can also use this link for some tutorials: http://php.net/manual/en/simplexml.examples-basic.php
This should work. You need to use attributes with type (if sting value use (string))
$id = (string) $xml->show->attributes()->id;
var_dump($id);
Or this:
$id = strip_tags($xml->show->attributes()->id);
var_dump($id);
You need to use attributes
I believe this should work
$id = $xml->show->attributes()->id;
You need to use attributes() to get the attributes.
$id = $xml->show->attributes()->id;
You can also do this:
$attr = $xml->show->attributes();
$id = $attr['id'];
Or you can try this:
$id = $xml->show['id'];
Looking at the edit to your question (<show>
is your root element), try this:
$id = $xml->attributes()->id;
OR
$attr = $xml->attributes();
$id = $attr['id'];
OR
$id = $xml['id'];
After you have correctly load the xml file using the SimpleXML objecto you can do a print_r($xml_variable)
and you can easily find which attributes you can access. As other users said $xml['id']
also worked for me.
try this
$id = (int)$xml->show->attributes()->id;