牛牛在线工具

DOMElement::getAttributeNames()

收录 8868 个 PHP 函数,含用途说明与用法示例。

DOMElement::getAttributeNames()

获取当前元素节点的所有属性名列表

函数名:DOMElement::getAttributeNames() 函数描述:该方法用于获取当前元素节点的所有属性名列表。 用法: array DOMElement::getAttributeNames ( void ) 注意事项: 该方法只能用于DOMElement类的实例。 如果元素节点不含有属性,则返回空数组。 示例: <?php // 创建一个简单的XML文档 $xml = new DOMDocument(); $xml->loadXML('<root id="1" name="example" />'); // 获取根节点元素 $root = $xml->documentElement; // 获取根节点元素的所有属性名 $attributeNames = $root->getAttributeNames(); // 输出属性名 foreach ($attributeNames as $name) { echo "Attribute Name: " . $name . "\n"; } ?> 输出: Attribute Name: id Attribute Name: name 在上面的示例中,我们首先创建了一个简单的XML文档,然后获取根节点的所有属性名,并将它们逐个输出到屏幕上。在这种情况下,根节点具有id和name两个属性。