0

我有 api 链接。当我调用此链接时,该链接将输出 xml 数据。

输出是

<note>
<something a="this is a" b="this is b" c="this is c">
<something a="this is a1" b="this is b1" c="this is c1">
<something a="this is a2" b="this is b2" c="this is c2">
<something a="this is a3" b="this is b3" c="this is c3">
</note>

我想得到一些东西的属性,我如何用 php 编写。我是 php 的初学者。感谢我的朋友。

我想写如下所示。我知道这个php代码有问题,如何正确编写。

foreach($xml->something[0]->attributes() as $a => $b)
  {
  echo $a,'="',$b,"\"</br>";
  }
?>
4

1 回答 1

0

你可以试试这个

$xml = simplexml_load_string($string);
foreach($xml->foo[0]->attributes() as $a => $b) {
    echo $a,'="',$b,"</br>";
}
于 2012-07-25T04:54:03.927 回答