Php/docs/tidy.parsestring

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

tidy::parseString

tidy_parse_string

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

tidy::parseString -- tidy_parse_string文字列にストアされたドキュメントをパースする


説明

オブジェクト指向型

public tidy::parseString ( string $string [, array|string|null $config = null [, string|null $encoding = null ]] ) : bool

手続き型

tidy_parse_string ( string $string [, array|string|null $config = null [, string|null $encoding = null ]] ) : tidy|false

文字列にストアされたドキュメントをパースします。


パラメータ

string

パースするデータ。

config

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

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

encoding

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


返り値

新しい tidy インスタンスを返します。 tidy_parse_string() は、成功時に新しい tidy インスタンスを返します。 これらのメソッド、関数は、失敗時に false を返します。


変更履歴

バージョン 説明
8.0.0 configencoding は、nullable になりました。


例1 tidy::parseString() の例

<?phpob_start();?><html>  <head>   <title>test</title>  </head>  <body>   <p>error<br>another line</i>  </body></html><?php$buffer = ob_get_clean();$config = array('indent' => TRUE,                'output-xhtml' => TRUE,                'wrap' => 200);$tidy = tidy_parse_string($buffer, $config, 'UTF8');$tidy->cleanRepair();echo $tidy;?>

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


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>
      test
    </title>
  </head>
  <body>
    <p>
      error<br />
      another line
    </p>
  </body>
</html>

参考

  • tidy::parseFile() - ファイルまたは URI にあるマークアップをパースする
  • tidy::repairFile() - ファイルを修正し、それを文字列として返す
  • tidy::repairString() - 別途提供される設定ファイルを使用して文字列を修正する