tidy_repair_string

(PHP 5)

tidy_repair_string --  Repair a string using an optionally provided configuration file

Description

string tidy_repair_string ( string data [, mixed config [, string encoding]] )

This function repairs the given string.

config 参数可以以数组或者字符串方式传递。如果以字符串传递,则代表配置文件名,否则就解释为选项本身。每个选项的解释见 http://tidy.sourceforge.net/docs/quickref.html

encoding 参数设置了输入/输出文档的编码方式。encoding 的可能值有:ascii,latin0,latin1,raw,utf8,iso2022,mac,win1252,ibm858,utf16,utf16le,utf16be,big5 和 shiftjis。

例子 1. tidy_repair_string() example

<?php
ob_start
();
?>

<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <p>error</i>
  </body>
</html>

<?php

$buffer
= ob_get_clean();
$tidy = tidy_repair_string($buffer);

echo
$tidy;
?>

上例将输出:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>test</title>
</head>
<body>
<p>error</p>
</body>
</html>

注: 可选参数 configencoding 是在 Tidy 2.0 中新加的。

See also tidy_parse_file(), tidy_parse_string() and tidy_repair_file().


add a note add a note User Contributed Notes
Atpic.com
14-May-2006 12:12
When using the function tidy_repair_string with the option show-body-only turned on to process pieces of HTML, I had to use trim() to remove the carriage returns that this function at the end of the resulting string.

function trimmed_tidy_repair_string($html){
   $config["show-body-only"]=true;
   $html=tidy_repair_string($html,$config,"utf8");
   $html=trim($html);
   return $html;
}