Php/docs/tidy.construct

提供:Dev Guides
< Php
移動先:案内検索

tidy::__construct

(PHP 5, PHP 7, PECL tidy >= 0.5.2)

tidy::__construct新しい tidy オブジェクトを作成する


説明

public tidy::__construct ([ string|null $filename = null [, array|string|null $config = null [, string|null $encoding = null [, bool $useIncludePath = false ]]]] )

新しい tidy オブジェクトを作成します。


パラメータ

filename

もし filename パラメータが与えられた場合、 この関数はファイルを読み込み、tidy_parse_file() のように実行してファイルに基づいたオブジェクトを初期化します。

config

config には配列あるいは文字列を渡します。 文字列を渡した場合は設定ファイルの名前、 それ以外の場合は設定そのものとして解釈されます。

オプションについての説明は » http://api.html-tidy.org/#quick-reference を参照ください。

encoding

encoding は入出力ドキュメントのエンコーディングを設定します。 指定できるエンコーディング名は asciilatin0latin1rawutf8iso2022macwin1252ibm858utf16utf16leutf16bebig5 および shiftjis です。

useIncludePath

include_path からファイルを探します。


返り値

新しい tidy インスタンスを返します。


変更履歴

バージョン 説明
8.0.0 filename, config,

encoding, useIncludePath は、nullable になりました。


例1 tidy::__construct() の例

<?php$html = <<< HTML<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd%22><html xmlns="http://www.w3.org/1999/xhtml%22 xml:lang="en" lang="en"><head><title>title</title></head><body><p>paragraph <bt />text</p></body></html>HTML;$tidy = new tidy();$tidy->ParseString($html);$tidy->cleanRepair();if ($tidy->errorBuffer) {    echo "The following errors were detected:\n";    echo $tidy->errorBuffer;}?>

上の例の出力は以下となります。


The following errors were detected:
line 8 column 14 - Error: <bt> is not recognized!
line 8 column 14 - Warning: discarding unexpected <bt>

参考

  • tidy::parseFile() - ファイルまたは URI にあるマークアップをパースする
  • tidy::parseString() - 文字列にストアされたドキュメントをパースする