Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: tidy - Manual
[go: Go Back, main page]

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

search for in the

ob_tidyhandler" width="11" height="7"/> <tcpwrap_check
Last updated: Sun, 25 Nov 2007

view this page in

Tidy 関数

導入

Tidyは、「Tidy HTML clean and repair utility」用のバインディングで、 HTML文書の誤りを直すだけでなく、操作することやドキュメントツリーを操作する ことも可能となります。

要件

Tidyを使用するには、libtidyがインストールされている必要があります。 libtidyは、tidyのホームページ » http://tidy.sourceforge.net/で入手可能です。

インストール手順

Tidy は、現在、PHP 4.3.xおよびPHP 5用として、PECL拡張モジュールとして » http://pecl.php.net/package/tidy. から入手可能です。

注意: Tidy 1.0 はPHP 4.3.x専用で、Tidy 2.0はPHP 5は専用です。

» PEAR は、 *nix互換のシステムで利用可能で、tidy拡張モジュールをインストールする際に 以下のようにpearインストーラを使用することができます。 : pecl install tidy

次のようにマニュアルでtar.gzパッケージをダウンロードし、tidyをインストール することも可能です。

Example#1 PHP 4.3.x において tidy をマニュアルでインストールする

gunzip tidy-xxx.tgz
tar -xvf tidy-xxx.tar
cd tidy-xxx
phpize
./configure && make && make install

Windows ユーザは、拡張モジュールの DLL を » http://pecl4win.php.net/ext.php/php_tidy.dll からダウンロードすることが可能です。

PHP5 においては、--with-tidy オプションを使ってコンパイルするだけです。

実行時設定

php.ini の設定により動作が変化します。

Tidy設定オプション
名前 デフォルト 変更の可否 変更履歴
tidy.default_config "" PHP_INI_SYSTEM PHP 5.0.0 以降で利用可能です。
tidy.clean_output "0" PHP_INI_USER PHP 5 では PHP_INI_PERDIR。PHP 5.0.0 以降で利用可能です。
PHP_INI_* 定数の詳細および定義については php.ini ディレクティブ を参照してください。

以下に設定ディレクティブに関する 簡単な説明を示します。

tidy.default_config string

tidy 設定ファイルへのデフォルトパス

tidy.clean_output boolean

Tidy による出力の修正のオン/オフを切り替える

警告

もし動的な画像のような HTML ではないコンテンツを生成する場合、 tidy.clean_output をオンにしないでください。

リソース型

リソース型は定義されていません。

定義済みクラス

tidyNode

メソッド

  • tidyNode::getParent - カレントノードの親を返します。

  • tidyNode->hasChildren - カレントノードが子を持つ場合、TRUE を返します。

  • tidyNode->hasSiblings - カレントノードが兄弟を持つ場合、TRUE を返します。

  • tidyNode->isAsp - カレントノードが ASP コードの場合、TRUE を返します。

  • tidyNode->isComment - カレントノードが コメントの場合、TRUE を返します。

  • tidyNode->isHtml - カレントノードが HTML の場合、TRUE を返します。

  • tidyNode->isJste - カレントノードが JSTE の場合、TRUE を返します。

  • tidyNode->isPhp - カレントノードが PHP の場合、TRUE を返します。

  • tidyNode->isText - カレントノードがテキスト (マークアップでない) の場合、 TRUE を返します。

プロパティ

  • value - ノードの値 (HTML テキストなど)

  • name - タグの名前 (html, a, など)

  • type - ノードの種類 (上記の定数の 1 つ。例えば TIDY_NODETYPE_PHP)

  • line* - ノードが開始する行

  • column* - ノードが開始するカラム

  • proprietary* - もしノードがプロプライエタリなタグの場合、 TRUE

  • id - タグの ID (上記の定数の 1 つ。例えば TIDY_TAG_FRAME)

  • attribute - カレントノードの属性の配列。存在しない場合 NULL

  • child - 子の tidyNode の配列。存在しない場合 NULL

注意: * 付きのプロパティは PHP 5.1.0 からのみ利用可能です。

定義済み定数

以下の定数が定義されています。 この関数の拡張モジュールが PHP 組み込みでコンパイルされているか、 実行時に動的にロードされている場合のみ使用可能です。

それぞれの TIDY_TAG_XXX は HTML タグに相当します。 例えば、 TIDY_TAG_A は <a href="XX">link</a> タグに相当します。 それぞれの TIDY_ATTR_XXX は、HTML 属性に相当します。 例えば、 TIDY_ATTR_HREF は前の例の href 属性に相当します。

以下の定数が定義されています。
tidy タグ定数
定数
TIDY_TAG_UNKNOWN
TIDY_TAG_A
TIDY_TAG_ABBR
TIDY_TAG_ACRONYM
TIDY_TAG_ALIGN
TIDY_TAG_APPLET
TID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DY_ATTR_XML_LANG
TIDY_ATTR_XML_SPACE
TIDY_ATTR_XMLNS

tidy ノード型定数
定数 説明
TIDY_NODETYPE_ROOT ルートノード
TIDY_NODETYPE_DOCTYPE 文章型
TIDY_NODETYPE_COMMENT HTML コメント
TIDY_NODETYPE_PROCINS 処理命令
TIDY_NODETYPE_TEXT テキスト
TIDY_NODETYPE_START 開始タグ
TIDY_NODETYPE_END 終了タグ
TIDY_NODETYPE_STARTEND 空タグ
TIDY_NODETYPE_CDATA CDATA
TIDY_NODETYPE_SECTION XML セクション
TIDY_NODETYPE_ASP ASP コード
TIDY_NODETYPE_JSTE JSTE コード
TIDY_NODETYPE_PHP PHP コード
TIDY_NODETYPE_XMLDECL XML 宣言

このシンプルな例は、Tidy の基本的な使い方を示しています。

Example#2 Tidy の基本的な使用法

<?php
ob_start
();
?>
<html>a html document</html>
<?php
$html 
ob_get_clean();

// とある設定
$config = array(
           
'indent'         => true,
           
'output-xhtml'   => true,
           
'wrap'           => 200);

// Tidy
$tidy = new tidy;
$tidy->parseString($html$config'utf8');
$tidy->cleanRepair();

// 出力
echo $tidy;
?>

目次

  • ob_tidyhandler — バッファを修正するための ob_start コールバック関数
  • tidy_access_count — 指定したドキュメントについて発生したTidyアクセシビリティ警告の数を返す
  • tidy_clean_repair — パースされたマークアップに設定に基く誤りの修正を行う
  • tidy_config_count — 指定したドキュメントについて発生した Tidy 設定エラーの数を返す
  • tidy::__construct — 新規 Tidy オブジェクトを生成する
  • tidy_diagnose — パース、修正されたマークアップの診断を行う
  • tidy_error_count — 指定したドキュメントについて発生した Tidy エラーの数を返す
  • tidy_get_body — Tidy パースツリーの タグから始まる tidyNode オブジェクトを返す
  • tidy_get_config — 現在の Tidy の設定を取得する
  • tidy_get_error_buffer — 指定したドキュメントのパースで発生した警告とエラーを返す
  • tidy_get_head — Tidy パースツリーの タグから始まる tidyNode オブジェクトを返す
  • tidy_get_html_ver — 指定したドキュメントで検出された HTML バージョンを取得する
  • tidy_get_html — Tidy パースツリーの タグから始まる tidyNode オブジェクトを返す
  • tidy_get_opt_doc — 与えられたオプション名に対するドキュメントを返す
  • tidy_get_output — パースされた Tidy マークアップを表す文字列を返す
  • tidy_get_release — Tidy ライブラリのリリース日 (バージョン) を取得する
  • tidy_get_root — Tidy パースツリーのルートを表す tidyNode を返す
  • tidy_get_status — 指定したドキュメントのステータスを取得する
  • tidy_getopt — Tidy ドキュメントについて指定した設定オプションの値を返す
  • tidy_is_xhtml — ドキュメントが XHTML ドキュメントかどうかを示す
  • tidy_is_xml — ドキュメントが一般的な XML ドキュメント (非 HTML/XHTML) かどうかを示す
  • tidy_load_config — 指定したエンコーディングで ASCII コードの Tidy 設定ファイルをロードする
  • tidy_node->get_attr — 指定された属性 ID を持つ属性を返す
  • tidy_node->get_nodes — 指定された ID を持つノード以下のノードの配列を返す
  • tidy_node->next — このノードの次の兄弟を返す
  • tidy_node->prev — このノードの前の兄弟を返す
  • tidy_parse_file — ファイルまたは URI にあるマークアップをパースする
  • tidy_parse_string — 文字列にストアされたドキュメントをパースする
  • tidy_repair_file — ファイルを修正し、それを文字列として返す
  • tidy_repair_string — 別途提供される設定ファイルを使用して文字列を修正する
  • tidy_reset_config — Tidy の設定をデフォルト値に戻す
  • tidy_save_config — 現在の設定を名前が付けられたファイルに保存する
  • tidy_set_encoding — マークアップをパースする際の入力/出力エンコーディングを設定する
  • tidy_setopt — 指定した Tidy ドキュメントについての設定を更新する
  • tidy_warning_count — 指定したドキュメントについて発生した Tidy 警告の数を返す
  • tidyNode->hasChildren — このノードが子を持つ場合 true を返す
  • tidyNode->hasSiblings — このノードが兄弟ノードを持つ場合 true を返す
  • tidyNode->isAsp — このノードが ASP コードの場合 true を返す
  • tidyNode->isComment — このノードがコメントである場合 true を返す
  • tidyNode->isHtml — このノードが HTML ドキュメントの場合 true を返す
  • tidyNode->isJste — このノードが JSTE であるの場合 true を返す
  • tidyNode->isPhp — このノードが PHP コードの場合 true を返す
  • tidyNode->isText — このノードがテキスト (マークアップでない) の場合 true を返す
  • tidyNode::getParent — カレントノードの親ノードを返す


ob_tidyhandler" width="11" height="7"/> <tcpwrap_check
Last updated: Sun, 25 Nov 2007
 
add a note add a note User Contributed Notes
tidy
badtzmari at gmail dot com
04-Dec-2007 12:52
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
Shuster
30-Oct-2007 04: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');
}

?>
Guillaume
15-May-2007 08: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"
matteo dot contri at tecem dot it
12-Oct-2006 05: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!
info att tcknetwork doot com
15-Jul-2006 07: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.
Paul Cook
12-Apr-2006 12: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.
patatraboum at nospam dot fr
26-Feb-2006 03: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>";
//
?>
tonygambone at gNOSPAMmail dot com
07-Feb-2006 01: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.
tom at expresshosting dot net
24-Aug-2005 02: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.
19-Feb-2005 08:47
There is a HTML/XHTML validator based on tidy at http://validator.aborla.net/

It is released under LGPL.
mohan at asix dot com dot my
11-Feb-2005 05: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
Jon Dowland (bugs at alcopop dot org)
01-Feb-2005 08: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.
14-Jan-2005 04:20
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>
doodleelephant
16-Nov-2004 10: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
bill dot mccuistion at qbopen dot com
30-Oct-2004 02: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.

ob_tidyhandler" width="11" height="7"/> <tcpwrap_check
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites