English | 简体中文 | 繁體中文
查询

tidy::__construct()函数—用法及示例

「 创建一个 Tidy 对象的实例 」


函数名:tidy::__construct()

函数描述:tidy::__construct() 函数用于创建一个 Tidy 对象的实例。

适用版本:PHP 5, PHP 7

用法:

Tidy::__construct ([ mixed $filename = NULL [, mixed $config = NULL [, mixed $encoding = NULL [, bool $use_include_path = FALSE ]]]] ) : Tidy

参数:

  • $filename(可选):一个字符串,表示要解析的文件名,如果不提供此参数,则会返回一个空的 Tidy 对象。
  • $config(可选):一个字符串,表示要加载的配置文件名,如果不提供此参数,则会使用默认的配置。
  • $encoding(可选):一个字符串,表示要使用的字符编码,默认为 "utf8"。
  • $use_include_path(可选):一个布尔值,表示是否使用 include_path 来查找文件,默认为 FALSE。

返回值:返回一个 Tidy 对象的实例。

示例:

// 创建一个 Tidy 对象实例
$tidy = new Tidy();

// 创建一个 Tidy 对象实例,并指定要解析的文件
$tidy = new Tidy('test.html');

// 创建一个 Tidy 对象实例,并指定要加载的配置文件
$tidy = new Tidy(NULL, 'tidy_config.txt');

// 创建一个 Tidy 对象实例,并指定字符编码和使用 include_path
$tidy = new Tidy(NULL, NULL, 'utf-8', true);

注意:tidy 模块需要在 PHP 中启用,并且需要安装 libtidy 库。

补充纠错
上一个函数: tidyNode::getParent()函数
下一个函数: tidy::root()函数
热门PHP函数
分享链接