如何使用php获取xml属性


How to get xml attributes with php?

我有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>";
  }
?>

你可以试试这个

$xml = simplexml_load_string($string);
foreach($xml->foo[0]->attributes() as $a => $b) {
    echo $a,'="',$b,"</br>";
}