note 102770 deleted from domnode.getlineno by danbrown
| From: | danbrown@php.net | Date: | Sat, 05 Mar 2011 15:38:19 +0000 |
| Subject: | note 102770 deleted from domnode.getlineno by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177580@lists.php.net to get a copy of this message | ||
Note Submitter: luke at webconnex dot com
----
This function is buggy. It doesn't always return the correct line number, especially for text
elements. As an alternative you can do something like this:
<?php
$text = $node->ownerDocument->saveXML($node);
$line += substr_count($text, "\n");
?>
You'll want to keep a reference to $line (starting at 0) and add to it as you parse over the
document recursively.
In order for this to work you have to tell DOMDocument to preserve white space before loading the
document.