PHP SimpleXML + Get Attribute

前端 未结 7 1282
猫巷女王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:58

    You need to format your XML properly and let it have examply using <root></root> or <document></document> anything .. see XML specification and examples at http://php.net/manual/en/function.simplexml-load-string.php

    $xml = '<?xml version="1.0" ?> 
    <root>
    <show id="8511">
        <name>The Big Bang Theory</name>
        <link>http://www.tvrage.com/The_Big_Bang_Theory</link>
        <started>2007-09-24</started>
        <country>USA</country>
    
        <latestepisode>
            <number>05x23</number>
            <title>The Launch Acceleration</title>
        </latestepisode>
    
    </show>
    </root>';
    
    $xml = simplexml_load_string ( $xml );
    var_dump ($xml->show->attributes ()->id);
    
    0 讨论(0)
提交回复
热议问题