【问题标题】:Access PHP SimpleXMLElement object访问 PHP SimpleXMLElement 对象
【发布时间】:2014-09-24 18:07:23
【问题描述】:

我有一个这样的对象:

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [url] => http://openclipart.org/people/jgm104/Expression_of_Emotions.svg
            [type] => image/svg+xml
            [length] => 485314
        )

)

如何从那里访问网址?

我试过$photos->item[$i]->enclosure->{"@attributes]"} 但它只显示空白的 SimpleXMLElement 对象。

【问题讨论】:

    标签: php xml-parsing


    【解决方案1】:

    您可以使用方法SimpleXMLElement::attributes 获取所有选项的访问权限。

    $photos->item[$i]->attributes()->url

    【讨论】:

      【解决方案2】:

      您可以通过以下方式访问它:

      $photos->item[$i]->enclosure->attributes()["attributeName"];
      

      $miAttrList = $photos->item[$i]->enclosure->attributes();
      echo $miAttrList["attributeName"];
      

      【讨论】:

        猜你喜欢
        • 2012-02-03
        • 1970-01-01
        • 2013-03-27
        • 2015-01-06
        • 1970-01-01
        • 1970-01-01
        • 2015-01-04
        • 2013-12-18
        • 1970-01-01
        相关资源
        最近更新 更多