Here's one example of a real life application of tidy parsing. Retrieves all the URLs in a document
<?php
function get_links($node) {
$urls = array();
/* Check to see if we are on an <A> tag or not */
if($node->id == TIDY_TAG_A) {
/* If we are, find the HREF attribute */
$attrib = $node->get_attr(TIDY_ATTR_HREF);
if($attrib) {
/* Add the value of the HREF attrib to $urls */
$urls[] = $attrib->value;
}
}
/* Are there any children? */
if($node->has_children()) {
/* Traverse down each child recursively */
foreach($node->children() as $child) {
/* Append the results from recursion to $urls */
foreach(get_links($child) as $url) {
$urls[] = $url;
}
}
}
return $urls;
}
?>