getName()

创建于 2024-12-03 / 50
字体: [默认] [大] [更大]

❮ PHP SimpleXML 参考手册

实例

返回 XML 元素及其子元素的名称:

<?php
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars>
  <car id="1">Volvo</car>
  <car id="2">BMW</car>
  <car id="3">Saab</car>
</cars>
XML;

$sxe=new SimpleXMLElement($xml);
// Get the name of the cars element
echo $sxe->getName() . "<br>";

// Also print out the names of the children of the cars element
foreach ($sxe->children() as $child)
  {
  echo $child->getName() . "<br>";
  }
?> 运行实例 »

定义和用法

getName() 函数返回 XML 元素的名称。


语法

SimpleXMLElement::getName()

技术细节

返回值: 以字符串形式返回 SimpleXML 元素引用的 XML 标签的名称。
PHP 版本: 5.1.3+

❮ PHP SimpleXML 参考手册
0 人点赞过