Wednesday, June 17, 2026
HomeLanguagesPHP | DOMNode getLineNo() function

PHP | DOMNode getLineNo() function

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
// Create a XML variable
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<root>
    <h1>neveropen</h1>
</root>
XML;
  
// Create a new DOMDocument instance
$dom = new DOMDocument;
  
// Load the XML
$dom->loadXML($xml);
  
// Print where the line where the 'node' element was defined in
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
// Create a XML variable
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<root>
    <h1>Geeks</h1>
    <h1>For</h1>
    <h1>Geeks</h1>
</root>
XML;
  
// Create a new DOMDocument instance
$dom = new DOMDocument();
  
// Load the XML
$dom->loadXML($xml);
  
for ($i = 0; $i < 3; $i++) {
    // Print where the line where the 'node' element was defined in
    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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS