PHP SimpleXML + Get Attribute

前端 未结 7 1353
猫巷女王i
猫巷女王i 2020-12-01 18:32

The XML I am reading looks like this:



    The Big Bang Theory
    http://www.tvrage.com/The_Bi         


        
7条回答
  •  忘掉有多难
    2020-12-01 18:47

    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 ( is your root element), try this:

    $id = $xml->attributes()->id;
    

    OR

    $attr = $xml->attributes();
    $id = $attr['id'];
    

    OR

    $id = $xml['id'];
    

提交回复
热议问题