DomElement->has_attribute()

Checks to see if an attribute exists in the current node ()

DomElement {
  bool has_attribute(string name);
}

This functions checks to see if an attribute named name exists in the current node.

参数

name

The name of the tested attribute.

返回值

Returns TRUE if the asked attribute exists, FALSE otherwise.

范例

例 505. Testing the existence of an attribute

<?php

include("example.inc");

if (!
$dom = domxml_open_mem($xmlstr)) {
   echo
"Error while parsing the document\n";
   exit;
}

$root = $dom->document_element();

$buffer = '<html';
if (
$root->has_attribute('language')) {
   
$buffer .= 'lang="' . $root->get_attribute('language') . '"';
}
$buffer .= '>';

?>

Migrating to PHP 5

Use DOMElement->hasAttribute().