Tidy Функции
Предопределенные классы
tidyNode
Методы
-
tidyNode::getParent - Returns the parent of the current node
-
tidyNode->hasChildren - Returns TRUE if the current node has children
-
tidyNode->hasSiblings - Returns TRUE if the current node has siblings
-
tidyNode->isAsp - Returns TRUE if the current node is ASP code
-
tidyNode->isComment - Returns TRUE if the current node is a comment
-
tidyNode->isHtml - Returns TRUE if the current node is HTML
-
tidyNode->isJste - Returns TRUE if the current node is JSTE
-
tidyNode->isPhp - Returns TRUE if the current node is PHP
-
tidyNode->isText - Returns TRUE if the current node is Text (no markup)
Свойства
-
value - the value of the node (e.g. the html text)
-
name - the name of the tag (e.g. html, a, etc..)
-
type - the type of the node (one of the constants above, e.g. TIDY_NODETYPE_PHP)
-
line* - the line where the node starts
-
column* - the column where the node starts
-
proprietary* - TRUE if the node refers to a proprietary tag
-
id - the ID of the tag (one of the constants above, e.g. TIDY_TAG_FRAME)
-
attribute - an array with the attributes of the current node, or NULL if there aren't any
-
child - an array with the child tidyNodes, or NULL if there aren't any
Замечание: The properties marked with * are just available since PHP 5.1.0.
Содержание
- ob_tidyhandler — ob_start callback function to repair the buffer
- tidy_access_count — Returns the Number of Tidy accessibility warnings encountered for specified document
- tidy_clean_repair — Execute configured cleanup and repair operations on parsed markup
- tidy_config_count — Returns the Number of Tidy configuration errors encountered for specified document
- tidy::__construct — Constructs a new tidy object
- tidy_diagnose — Run configured diagnostics on parsed and repaired markup
- tidy_error_count — Returns the Number of Tidy errors encountered for specified document
- tidy_get_body — Returns a tidyNode Object starting from the tag of the tidy parse tree
- tidy_get_config — Get current Tidy configuration
- tidy_get_error_buffer — Return warnings and errors which occurred parsing the specified document
- tidy_get_head — Returns a tidyNode Object starting from the tag of the tidy parse tree
- tidy_get_html_ver — Get the Detected HTML version for the specified document
- tidy_get_html — Returns a tidyNode Object starting from the tag of the tidy parse tree
- tidy_get_opt_doc — Returns the documentation for the given option name
- tidy_get_output — Return a string representing the parsed tidy markup
- tidy_get_release — Get release date (version) for Tidy library
- tidy_get_root — Returns a tidyNode object representing the root of the tidy parse tree
- tidy_get_status — Get status of specified document
- tidy_getopt — Returns the value of the specified configuration option for the tidy document
- tidy_is_xhtml — Indicates if the document is a XHTML document
- tidy_is_xml — Indicates if the document is a generic (non HTML/XHTML) XML document
- tidy_load_config — Load an ASCII Tidy configuration file with the specified encoding
- tidy_node->get_attr — Return the attribute with the provided attribute id
- tidy_node->get_nodes — Return an array of nodes under this node with the specified id
- tidy_node->next — Returns the next sibling to this node
- tidy_node->prev — Returns the previous sibling to this node
- tidy_parse_file — Parse markup in file or URI
- tidy_parse_string — Parse a document stored in a string
- tidy_repair_file — Repair a file and return it as a string
- tidy_repair_string — Repair a string using an optionally provided configuration file
- tidy_reset_config — Restore Tidy configuration to default values
- tidy_save_config — Save current settings to named file
- tidy_set_encoding — Set the input/output character encoding for parsing markup
- tidy_setopt — Updates the configuration settings for the specified tidy document
- tidy_warning_count — Returns the Number of Tidy warnings encountered for specified document
- tidyNode->hasChildren — Returns true if this node has children
- tidyNode->hasSiblings — Returns true if this node has siblings
- tidyNode->isAsp — Returns true if this node is ASP
- tidyNode->isComment — Returns true if this node represents a comment
- tidyNode->isHtml — Returns true if this node is part of a HTML document
- tidyNode->isJste — Returns true if this node is JSTE
- tidyNode->isPhp — Returns true if this node is PHP
- tidyNode->isText — Returns true if this node represents text (no markup)
- tidyNode::getParent — returns the parent node of the current node
Коментарии
Installing tidy on Fedora Core 2 required three libraries:
tidy...
tidy-devel...
libtidy...
All of which I found at http://rpm.pbone.net
Then, finally, could "./configure --with-tidy"
Hope this helps someone out. This was "REALLY" hard (for me) to figure out as no where else was clearly documented.
<?php
//
//The tidy tree of your favorite !
//For PHP 5 (CGI)
//Thanks to john@php.net
//
$file="http://www.php.net";
//
$cns=get_defined_constants(true);
$tidyCns=array("tags"=>array(),"types"=>array());
foreach($cns["tidy"] as $cKey=>$cVal){
if($cPos=strpos($cKey,$cStr="TAG")) $tidyCns["tags"][$cVal]="$cStr : ".substr($cKey,$cPos+strlen($cStr)+1);
elseif($cPos=strpos($cKey,$cStr="TYPE")) $tidyCns["types"][$cVal]="$cStr : ".substr($cKey,$cPos+strlen($cStr)+1);
}
$tidyNext=array();
//
echo "<html><head><meta http-equiv='Content-Type' content='text/html; charset=windows-1252'><title>Tidy Tree :: $file</title></head>";
echo "<body><pre>";
//
tidyTree(tidy_get_root(tidy_parse_file($file)),0);
//
function tidyTree($tidy,$level){
global $tidyCns,$tidyNext;
$tidyTab=array();
$tidyKeys=array("type","value","id","attribute");
foreach($tidy as $pKey=>$pVal){
if(in_array($pKey,$tidyKeys)) $tidyTab[array_search($pKey,$tidyKeys)]=$pVal;
}
ksort($tidyTab);
foreach($tidyTab as $pKey=>$pVal){
switch($pKey){
case 0 :
if($pVal==4) $value=true; else $value=false;
echo indent(true,$level).$tidyCns["types"][$pVal]."\n"; break;
case 1 :
if($value){
echo indent(false,$level)."VALEUR : ".str_replace("\n","\n".indent(false,$level),$pVal)."\n";
}
break;
case 2 :
echo indent(false,$level).$tidyCns["tags"][$pVal]."\n"; break;
case 3 :
if($pVal!=NULL){
echo indent(false,$level)."ATTRIBUTS : ";
foreach ($pVal as $aKey=>$aVal) echo "$aKey=$aVal "; echo "\n";
}
}
}
if($tidy->hasChildren()){
$level++; $i=0;
$tidyNext[$level]=true;
echo indent(false,$level)."\n";
foreach($tidy->child as $child){
$i++;
if($i==count($tidy->child)) $tidyNext[$level]=false;
tidyTree($child,$level);
}
}
else echo indent(false,$level)."\n";
}
//
function indent($tidyType,$level){
global $tidyNext;
$indent="";
for($i=1;$i<=$level;$i++){
if($i<$level||!$tidyType){
if($tidyNext[$i]) $str="| "; else $str=" ";
}
else $str="+--";
$indent=$indent.$str;
}
return $indent;
}
//
echo "</pre></body></html>";
//
?>