PHP | DOMNode getLineNo() function
Last Updated :
25 Feb, 2020
The DOMNode::getLineNo() function is an inbuilt function in PHP which is used to get the line number for where the node is defined.
Syntax:
DOMNode DOMNode::getLineNo( void )
Parameters:This function doesn’t accept any parameter.
Return Value: This function returns the line number where the node was defined in.
Below given programs illustrate the DOMNode::getLineNo() function in PHP:
Program 1:
<?php
$xml = <<<XML
<?xml version= "1.0" encoding= "utf-8" ?>
<root>
<h1>GeeksforGeeks</h1>
</root>
XML;
$dom = new DOMDocument;
$dom ->loadXML( $xml );
echo 'The <node> tag is defined on line ' . $dom ->getElementsByTagName( 'h1' )->item(0)->getLineNo();
?>
|
Output:
The tag is defined on line 3
Program 2:
<?php
$xml = <<<XML
<?xml version= "1.0" encoding= "utf-8" ?>
<root>
<h1>Geeks</h1>
<h1>For</h1>
<h1>Geeks</h1>
</root>
XML;
$dom = new DOMDocument();
$dom ->loadXML( $xml );
for ( $i = 0; $i < 3; $i ++) {
echo $i . ') The h1 tag is defined on line ' . $dom ->getElementsByTagName( 'h1' )->item( $i )->getLineNo() . "<br>" ;
}
?>
|
Output:
0) The h1 tag is defined on line 3
1) The h1 tag is defined on line 4
2) The h1 tag is defined on line 5
Reference: https://www.php.net/manual/en/domnode.getlineno.php
Share your thoughts in the comments
Please Login to comment...