📜  PHP | DOMNode getLineNo()函数

📅  最后修改于: 2022-05-13 01:56:41.639000             🧑  作者: Mango

PHP | DOMNode getLineNo()函数

DOMNode::getLineNo()函数是PHP中的一个内置函数,用于获取定义节点的行号。

句法:

DOMNode DOMNode::getLineNo( void )

参数:此函数不接受任何参数。

返回值:此函数返回定义节点的行号。

下面给出的程序说明了PHP中的DOMNode::getLineNo()函数
方案一:



    

GeeksforGeeks

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 tag is defined on line ' . $dom->getElementsByTagName('h1')->item(0)->getLineNo(); ?>

输出:

The tag is defined on line 3

方案二:



    

Geeks

    

For

    

Geeks

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() . "
";    } ?>

输出:

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

参考: https://www. PHP.net/manual/en/domnode.getlineno。 PHP