Using DOM textContent Property

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I am writing a filter in PHP that takes some HTML as input and goes through
the HTML and adjusts certain tag attributes as needed.  So, for example, if
<a> tag is missing the "title" attribute, this filter adds a title attribute
to the <a> tag.

I'm doing this all using PHP 5 and the DOM parsing library, and it's working
really well.

The one snafu I'm running in to is dealing with users who will just type an
e-mail address into an HTML document without actually making it a link - so,
they'll just put foo@xxxxxxx rather than <a
href="mailto:foo@xxxxxxx";>foo@xxxxxxx</a>.  I'd like for these incorrectly
entered e-mail addresses to magically change into real clickable links, so
I'd like my filter to be able to grab those plain text e-mail addresses and
convert them to actual clickable links.

I tried iterating through all the elements on a page using something like
this:

$Elements = $HTML->getElementsByTagName("*");

for ($X = 0; $X < $Elements->length; $X++) {
  ... SNIP ...
}

And then I tried looking at the textContent property of each node, but it
seems that higher-level nodes include all the text of their children nodes
(which is what the DOM documents say it should).  But there doesn't appear
to be any way to know if the textContent you've got is for just one node, or
for a whole bunch of nodes.  Is there any way to figure that out, so that I
can adjust the textContent property of just the lowest-level nodes, rather
than mucking up the higher-level ones?

Tim Gustafson
SOE Webmaster
UC Santa Cruz
tjg@xxxxxxxxxxxx
831-459-5354



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux