I’m creating a tool that works with file strings and I need to get the line number where a node is found. It is, I have this:
$dom = new DOMDocument('1.0');
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
foreach ($xpath->query("//text()") as $q) {
// $line = WHAT???
$strings[trim($q->nodeValue)] = $line;
}
and I need to know in which line begins the string I’m storing in $strings array. Is it possible to get it?
Each
DOMNodeobject has agetLineNo()function that returns this. In your case it’s aDOMTextobject that extends fromDOMNode:You might need to upgrade to PHP 5.3 if you have not yet to make use of that function.