PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

tidy_get_status> <tidy_get_release
Last updated: Fri, 05 Sep 2008

view this page in

tidy_get_root

(PHP 5, PECL tidy:0.5.2-1.0)

tidy_get_rootReturns a tidyNode object representing the root of the tidy parse tree

Description

Procedural style:

tidyNode tidy_get_root ( tidy $object )

Object oriented style:

tidyNode tidy->root ( void )

Returns a tidyNode object representing the root of the tidy parse tree.

Пример #1 dump nodes

<?php

$html 
= <<< HTML
<html><body>

<p>paragraph</p>
<br/>

</body></html>
HTML;

$tidy tidy_parse_string($html);
dump_nodes($tidy->root(), 1);


function 
dump_nodes($node$indent) {

    if(
$node->hasChildren()) {
        foreach(
$node->child as $child) {
            echo 
str_repeat('.'$indent*2) . ($child->name $child->name '"'.$child->value.'"'). "\n";

            
dump_nodes($child$indent+1);
        }
    }
}
?>

Результат выполнения данного примера:

..html
....head
......title
....body
......p
........"paragraph"
......br

Замечание: Эта функция доступна только в Движке Zend 2, что означает PHP >= 5.0.0.



add a note add a note User Contributed Notes
tidy_get_root
james dot ellis at gmail dot com
11-Dec-2007 02:11
To avoid temporary insanity, it's worth noting that if you are pushing HTML through tidy with the show-body-only option set to TRUE, then calling tidy->root() will return the HTML including doctype, html, head, title tags etc.
To get your body only HTML, do the usual thing of casting the tidy object as a string.

<?php
//assume $config and $encoding are set for this example
$markup = "<h2>Welc<foo>ome</h2>";
$tidy = new Tidy;
$tidy->parseString($markup, $config, $encoding);
$tidy->cleanRepair();
print (string)
$tidy->root();
/**
result:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<h2>Welcome</h2>
</body>
</html>
*/
print (string)$tidy;
/**
result:
<h2>Welcome</h2>
*/
?>

tidy_get_status> <tidy_get_release
Last updated: Fri, 05 Sep 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites