PHP | DOMAttr isId() Function Last Updated : 03 Sep, 2021 Comments Improve Suggest changes Like Article Like Report The DOMAttr::isId() function is an inbuilt function in PHP which is used to check if an attribute is a defined ID or not. According to the DOM standard, it requires the attribute ID to be of type ID. You need to validate your document with DOMDocument::validateOnParse() method before using this function. Syntax: bool DOMAttr::isId( void ) Parameters: This function doesn’t accept any parameters.Return Value: This function returns TRUE if it contained an id attribute otherwise returns FALSE. Below given programs illustrate the DOMAttr::isId() function in PHP: Program 1: PHP <?php // Create a new DOM Document $dom = new DOMDocument('1.0', 'iso-8859-1'); // Enable validate on parse $dom->validateOnParse = true; // Create a div element $element = $dom->appendChild(new DOMElement('div')); // Create a class attribute $attr = $element->setAttributeNode( new DOMAttr('class', 'geekforgeeks')); // Get the attribute $getattr = $dom->getElementsByTagName('div') ->item(0)->getAttributeNode('class'); // Check if it is id or not if($getattr->isId()) { echo 'Yes, this is an id'; } else { echo 'No, this is not an id'; } ?> Output: No, this is not an id Program 2: PHP <?php // Create a new DOM Document $dom = new DOMDocument('1.0', 'iso-8859-1'); // Enable validate on parse $dom->validateOnParse = true; // Create a div element $element = $dom->appendChild(new DOMElement('div')); // Create a id attribute $attr = $element->setAttributeNode( new DOMAttr('id', 'mynewid')); // Set that attribute as id $element->setIDAttribute('id', true); // Get the attribute $getattr = $dom->getElementsByTagName('div') ->item(0)->getAttributeNode('id'); // Check if it is id or not if($getattr->isId()) { echo 'Yes, this is an id'; } else { echo 'No, this is not an id'; } ?> Output: Yes, this is a id Reference: https://www.php.net/manual/en/domattr.isid.php Comment More infoAdvertise with us Next Article PHP | DOMAttr isId() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads PHP | is_a() function The is_a() is a built-in function in PHP and is used to check whether a given object is of a given class or not. It also checks if the given class is one of the parents of the given object or not. Syntax: boolean is_a($object, $class) Parameters: This function accepts two parameters as shown in the 2 min read PHP | filter_id() Function The filter_id() function is an inbuilt function in PHP which returns the filter ID of a specified filter name. It is used to get the filter id of the particular filter in PHP by using filter_id function by giving the name of the filter as input and get the associated id to it. Syntax: int filter_id( 2 min read PHP | DOMAttr __construct() Function The DOMAttr::__construct() function is an inbuilt function in PHP which is used to create a new DOMAttr object. This created object is a read-only type. Syntax: public DOMAttr::__construct( string $name, string $value ) Parameters: This function accepts two parameters as mentioned above and describe 2 min read PHP | DOMNode isSameNode() Function The DOMNode::isSameNode() function is an inbuilt function in PHP which indicates if two nodes are the same node or not. Syntax: bool DOMNode::isSameNode( DOMNode $node ) Parameters: This function accepts a single parameter $node which holds the node to be compared. Return Value: This function return 2 min read PHP | DOMCharacterData insertData() Function The DOMCharacterData::insertData() function is an inbuilt function in PHP which is used to insert a string at the specified 16-bit unit offset. Syntax: void DOMCharacterData::insertData( int $offset, string $data ) Parameters: This function accept two parameters as mentioned above and described belo 2 min read Like