The manual doesn't really make it clear that the PECL ext is only for php4. For php5, you have to use the --with-tidy option. (At least, this was the case for me with php 5.2.5 on Mac OS 10.4 - Tiger.) Tiger ships with tidylibs already installed in /usr/include but there is broken header file. The easiest way to get php to compile with Tidy on 10.4 (and 10.5 Leopard also) is to download Macports and use that to install tidy (unless you want to build tidy from src.) After installing Macports via the .dmg, just su root and do:
port install tidy
(port is installed in /opt/local/bin)
Then configure --with-tidy=/opt/local (Macports installs stuff in /opt/local).
You can also use Macports to install all sorts of other libs such as png, libmcrypt, freetype and jpeg (although libpng and libjpeg are also available as package installs.)
The specific compile error is:
In file included from /usr/include/tidy/tidy.h:70,
from /Users/mari/Downloads/php-5.2.5/ext/tidy/
tidy.c:34:
/usr/include/tidy/platform.h:515: error: duplicate 'unsigned'
/usr/include/tidy/platform.h:515: warning: useless type name in empty declaration
Funkcje Tidy
Klasy predefiniowane
tidyNode
Metody
-
tidyNode::getParent - Zwraca przodka bieżącego węzła
-
tidyNode->hasChildren - Zwraca TRUE jeżeli bieżący węzeł posiada potomków
-
tidyNode->hasSiblings - Zwraca TRUE jeżeli bieżący węzeł posiada sąsiadów
-
tidyNode->isAsp - Zwraca TRUE jeżeli bieżący węzeł jest kodem ASP
-
tidyNode->isComment - Zwraca TRUE jeżeli bieżący węzeł jest komentarzem
-
tidyNode->isHtml - Zwraca TRUE jeżeli bieżący węzeł jest kodem HTML
-
tidyNode->isJste - Zwraca TRUE jeżeli bieżący węzeł jest kodem JSTE
-
tidyNode->isPhp - Zwraca TRUE jeżeli bieżący węzeł jest kodem PHP
-
tidyNode->isText - Zwraca TRUE jeżeli bieżący węzeł jest czystym tekstem (nie jest kodem)
Właściwości
-
value - wartość węzła (np. tekst)
-
name - nazwa znacznika (np. html, a, itd.)
-
type - typ węzła (jedna z poniższych stałych, np. TIDY_NODETYPE_PHP)
-
line* - linia w której zaczyna się węzeł
-
column* - kolumna w której zaczyna się węzeł
-
proprietary* - TRUE jeżeli węzeł wskazuje na niekompatybilny znacznik
-
id - identyfikator ID znacznika (jeden z poniższych, np. TIDY_TAG_FRAME)
-
attribute - tablica zawierająca argumenty bieżącego węzła, lub NULL jeśli nie występują
-
child - tablica zawierająca potomków węzłów uporządkowanych przez Tidy, lub NULL jeżeli nie występują
Informacja: Właściwości oznaczone symbolem * są dostępne od PHP 5.1.0.
Spis treści
- ob_tidyhandler — Funkcja zwrotna do czyszczenia bufora wyjścia dla funkcji ob_start
- tidy_access_count — Zwraca liczbę dostępnych ostrzeżeń napotkanych w określonym dokumencie
- tidy_clean_repair — Wykonuje operacje czyszczenia i poprawiania składni znaczników zgodnie z określoną konfiguracją
- tidy_config_count — Zwraca liczbę błędów konfiguracji Tidy napotkanych w określonym dokumencie
- tidy::__construct — Tworzy nowy obiekt Tidy
- tidy_diagnose — Uruchamia diagnostykę skonfigurowaną dla parsowanych i reperowanych znaczników
- tidy_error_count — Zwraca liczbę błędów Tidy znalezionych w określonym dokumencie
- tidy_get_body — Zwraca obiekt tidyNode zaczynający się od znacznika w parsowanym drzewie Tidy
- tidy_get_config — Zwraca bieżącą konfigurację Tidy
- tidy_get_error_buffer — Zwraca ostrzeżenia i błędy jakie wystąpiły podczas parsowania określonego dokumentu
- tidy_get_head — Zwraca obiekt tidyNode zaczynający się od znacznika w parsowanym drzewie Tidy
- tidy_get_html_ver — Zwraca wersję HTML w określonym dokumencie
- tidy_get_html — Zwraca obiekt tidyNode zaczynający się od znacznika w parsowanym drzewie Tidy
- tidy_get_opt_doc — Zwraca dokumentację dla danej nazwy opcji
- tidy_get_output — Zwraca łańcuch zawierający poprawiony przez Tidy kod HTML, XHTML lub XML
- tidy_get_release — Zwraca datę wydania (wersję) biblioteki Tidy
- tidy_get_root — Zwraca obiekt tidyNode przedstawiający korzeń parsowanego drzewa Tidy
- tidy_get_status — Zwraca status określonego dokumentu
- tidy_getopt — Zwraca wartość określonej opcji konfiguracyjnej dla obiektu Tidy
- tidy_is_xhtml — Sprawdza, czy kod jest dokumentem XHTML
- tidy_is_xml — Sprawdza, czy kod jest ogólnym dokumentem XML (nie HTML/XHTML)
- tidy_load_config — Wczytuje plik konfiguracyjny Tidy w formacie ASCII z określonym kodowaniem znaków narodowych
- tidy_node->get_attr — Zwraca wartość atrybutu dla podanego identyfikatora atrybutu
- tidy_node->get_nodes — Zwraca tablice węzłów znajdujących się poniżej bieżącego węzła z określonym identyfikatorem
- tidy_node->next — Zwraca następnego sąsiada bieżącego węzła
- tidy_node->prev — Zwraca poprzedniego sąsiada bieżącego węzła
- tidy_parse_file — Parsuje znaczniki z pliku lub URI
- tidy_parse_string — Parsuje dokument przechowywany w łańcuchu
- tidy_repair_file — Naprawia plik i zwraca go w postaci łańcucha
- tidy_repair_string — Poprawia składnię znaczników w łańcuchu znaków, używając opcjonalnie wskazanego pliku konfiguracyjnego
- tidy_reset_config — Przywraca domyślne wartości konfiguracji Tidy
- tidy_save_config — Zapisuje bieżące ustawienia konfiguracyjne Tidy we wskazanym pliku
- tidy_set_encoding — Ustawia kodowanie znaków narodowych dla dokumentów wejściowych i wyjściowych
- tidy_setopt — Uaktualnia ustawienia konfiguracji dla określonego dokumentu tidy
- tidy_warning_count — Zwraca liczbę ostrzeżeń Tidy znalezionych w określonym dokumencie
- tidyNode->hasChildren — Zwraca prawdę, jeśli węzeł posiada potomka
- tidyNode->hasSiblings — Zwraca prawdę, jeśli węzeł posiada sąsiadów
- tidyNode->isAsp — Zwraca prawdę, jeśli węzeł jest kodem ASP (Active Server Pages)
- tidyNode->isComment — Zwraca prawdę, jeśli węzeł jest komentarzem
- tidyNode->isHtml — Zwraca prawdę, jeśli węzeł jest częścią dokumentu HTML
- tidyNode->isJste — Zwraca prawdę, jeśli węzeł jest kodem JSTE (ang. JavaScript Template Engine)
- tidyNode->isPhp — Zwraca prawdę, jeśli węzeł jest kodem PHP
- tidyNode->isText — Zwraca prawdę, jeśli węzeł jest tekstem (nie jest znacznikiem)
- tidyNode::getParent — zwraca rodzica bieżącego węzła
Funkcje Tidy
03-Dec-2007 07:52
29-Oct-2007 12:45
Valid XHTML STRICT
<?php
if (function_exists('tidy_repair_string'))
{
$xhtml = tidy_repair_string($xhtml, array('output-xhtml' => true, 'show-body-only' => true, 'doctype' => 'strict', 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'lower-literals' => true, 'quote-ampersand' => true, 'wrap' => 0), 'raw');
}
?>
15-May-2007 04:36
To install correctly Tidy for PHP5 on Ubuntu, follow this link :
http://ubuntuforums.org/showthread.php?t=195636
In fact, you need to run a "make clean" before the commands "make" and "make install"
12-Oct-2006 01:44
i had many problem with a javascript that grab mouse event on image and tidy (obviously).
I found this solution:
'output-xhtml' => false
and everything is working again!
15-Jul-2006 03:23
I have been searching for an easy way to check an entire website against HTML/XHTML formatting (no error, compilant, etc.), tidy is very useful for that :
<?php
/** aready checked pages */
$e=array();
/** webpages to check */
$t=array("/web/test.com/");
/** forbidden extensions (typically linked ressources) */
$x=explode(",","jpg,gif,png,doc,xls,pdf");
echo "<pre>";
while ($t[0]) {
// already checked or a ressource => skip
if (in_array($t[0],$e) || in_array(substr($t[0],-3),$x)) array_shift($t);
else { $c=array_shift($t); $e[]=$c; $t=array_merge($t,ck($c)); }
}
echo "</pre>";
/**
check_vailidty($url,$server)
return : list of the internal links of the page
*/
function ck($u,$s="http://127.0.0.1") {
$c=array("indent"=>1,"output-xhtml"=>1,"accessibility-check"=>3);
$t=tidy_parse_string(file_get_contents($s.$u),$c);
tidy_clean_repair($t);
if (tidy_error_count($t)) { // we have error, display them
echo "FAIL ".htmlentities($u)." (".tidy_error_count($t)." errors)\n";
echo htmlentities(tidy_get_error_buffer($t))."\n";
} else { // all right
echo "OK ".htmlentities($u)."\n";
}
// return all the links inside the page
return gl(tidy_get_root($t),substr($u,-1)=="/"?$u:dirname($u)."/");
}
/**
get_links($tinynode,$baseurl)
return : list of the links
*/
function gl($t,$b) {
$r=array();
$c=count($t->child);
for ($i=0;$i<$c;$i++) {
$e=&$t->child[$i];
if ($e->name=="a") { // a link
$h=$e->attribute["href"]; // url
if (substr($h,0,4)!="http") { // prevent external links
$r[]=sp(substr($h,0,1)=="/"?$h:$b.$h);
}
} else { // not a link, search recursively inside
$r=array_merge($r,gl($e,$b));
}
}
return $r;
}
/**
simplify_path($path)
return : simplified path
*/
function sp($p) {
while ($o!=$p) {
$o=$p;
$p=str_replace(array("//","/./"),"/",$p);
$p=preg_replace("/\/[^\/]+\/..\//","/",$p);
}
return $p;
}
?>
Limitation : does not detect javascript-generated links. Check about set_time_limit(0) if you have a lot of webpages.
11-Apr-2006 08:25
To get libtidy and PHP 5.0.5 compiled on OS X Tiger this is what I needed to do:
1) download and upack the tidy source.
2) cd tidy-source-dir
3) >> /bin/sh build/gnuauto/setup.sh
4) then you can configure/make/make install as normal
PHP build generates errors because of tidy so I needed to edit the platform.h file like this (use your favorite command line editor):
5) >> sudo emacs /usr/local/include/platform.h
6) comment out line 508 which was causing the 'duplicate "unsigned" ' error in the PHP build.
7) configure/make/make install PHP as normal using --with-tidy=/usr/local
Restart apache and everything works now. HTH someone.
25-Feb-2006 10:13
<?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>";
//
?>
06-Feb-2006 08:03
Using PHP 5.1.2 on Win32/IIS, I noticed that even with "output-xhtml: yes," tidy was adding the deprecated name attribute to form tags (using the value of the id attribute). Grabbing the latest dll from the snaps link at the top of the page fixed this.
23-Aug-2005 10:50
It should be noted that the examples on this page apply ONLY to PHP5. None of the functions in the manual apply to PHP4. The names are the same but arguments are different on some of them (tidy_parse_string).
If you wish to use tidy in PHP 4.3.x you can use the following example instead:
<?php
$tidyhtml = ob_get_contents();
if( function_exists( 'tidy_parse_string' ) ) {
tidy_set_encoding('iso-8859-1');
tidy_parse_string($tidyhtml);
tidy_setopt('output-xhtml', TRUE);
tidy_setopt('indent', TRUE);
tidy_setopt('indent-spaces', 2);
tidy_setopt('wrap', 200);
tidy_clean_repair();
$tidyhtml = tidy_get_output();
}
ob_end_clean();
echo $tidyhtml;
?>
Hope that helps somebody.
There is a HTML/XHTML validator based on tidy at http://validator.aborla.net/
It is released under LGPL.
11-Feb-2005 12:23
To those who need to install libtidy on mac os x , here is a guide that worked for me :
If you're on Mac OS X, you'll need to tell the Makefile that you use
ranlib:
$ export set RANLIB=ranlib
Change to the directory with the Makefile in it, and run make.
This example uses the GNU make Makefile.
$ cd tidy/build/gmake/
$ make
if [ ! -d ./obj ]; then mkdir ./obj; fi
gcc -o obj/access.o ...
... etc etc etc ...
Install the libs, headers and the tidy executable:
$ sudo make install
If you're on Mac OS X, you'll have to run ranlib again on the installed
lib:
$ sudo ranlib /usr/local/lib/libtidy.a
01-Feb-2005 03:40
Rough installation instructions for debian/testing:
Use debian's apt package manager to install the required development packages
$ apt-get install php4-dev php4-pear libtidy-dev
Then use pear to install tidy
$ pear install tidy
Note: I did /not/ have success installing the tarball locally. Only using this method was the .so put in the correct place.
I also had to add an entry to the php.ini
$ echo extension=tidy.so >> /etc/php4/apache/php.ini
$ apachectl restart
...and you're done.
Just in case anyone else has been having problems using the tidy extension in *PHP4 v4.3.10. Here is a working example:
$html = '<HTML><HEAD></HEAD><BODY>Hello World</BODY></HTML>';
$config = array('indent'=> TRUE,
'output-xhtml' => TRUE,
'wrap' => 80);
tidy_set_encoding('UTF8');
foreach ($config as $key => $value) {
tidy_setopt($key,$value);
}
tidy_parse_string($html);
tidy_clean_repair();
echo tidy_get_output();
Resultant HTML should be similar to:
<!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>
Hello World
</body>
</html>
15-Nov-2004 05:34
I'm installing PHP 5.0.2 on Redhat Linux (I forget the version. Enterprise WS 3 I think) I had troubles installing the libtidy. It consistently complained that it could not find 'libtidy'. I finally got a clue into how to install it (in build/gnuauto/readme.txt). This is how I finally got it to install (after lots of trial and error):
First, don't get the binary distribution of of tidy.sf.net. It's not what you want. You need the source distribution.
Command by command this is what I did:
=======
wget http://tidy.sourceforge.net/src/tidy_src.tgz
tar -xzf tidy_src.tgz
cd tidy
/bin/sh build/gnuauto/setup.sh
./configure --prefix=/usr
make
make install
cd [php source directory]
./configure --with-tidy=/usr --[other extensions]
make
make install
=======
Tada. Finally it doesn't complain when I configure PHP about the installation. The info I needed was stuck in that build/gnuauto/readme.txt file in the tidy directory.
Took me a while. Hope my trials can help others save time.
Doodleelephant
29-Oct-2004 10:53
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.
