2016-06-14 14 views

回答

0

可以使用DOMNode::getLineNo()其工作方式如下:

<?php 
// XML dump for below example 
$xml = <<<XML 
<?xml version="1.0" encoding="utf-8"?> 
<root> 
    <node /> 
</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 
printf('The <node> tag is defined on line %d', $dom->getElementsByTagName('node')->item(0)->getLineNo()); 
?> 

上例將輸出:

標籤處於線限定3.

供參考:幾年前,由於libxml2錯誤,這種方法停止工作,但我做了一個在線小提琴,它的工作。

相關問題