• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • tidy::parseFile()

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

    分析文件或URI中的标记

    说明

    面向对象风格
    publictidy::parseFile(string $filename[,mixed $config[,string $encoding[,bool $use_include_path= FALSE]]]): bool
    过程化风格
    tidy_parse_file(string $filename[,mixed $config[,string $encoding[,bool $use_include_path= FALSE]]]): tidy

    参数

    • $filename:如果给定了$filename参数,此函数还将读取该文件并用该文件初始化对象,其作用如tidy_parse_file()
    • $config:配置选项可以作为数组或字符串传递。如果传递字符串,则将其解释为配置文件的名称,否则,将其解释为选项本身.
    • $encoding:编码参数设置输入/输出文档的编码。可能的编码值是:ascii,latin0,latin1,raw,utf8,iso2022,mac,win1252,ibm858,utf16,utf16le,utf16be,big5, andshiftjis
    • $use_include_path:在包含路径中搜索文件。

    返回值

    成功时返回TRUE,或者在失败时返回FALSE

    范例

    <?php
    $tidy = new tidy();
    $tidy->parseFile('file.html');
    $tidy->cleanRepair();
    if(!empty($tidy->errorBuffer)) {
        echo "The following errors or warnings occurred:\n";
        echo $tidy->errorBuffer;
    }
    ?>
    

    参见

    • tidy::parsestring() 分析存储在字符串中的文档
    • tidy::repairfile() 修复文件并将其作为字符串返回
    • tidy::repairstring() 使用可选提供的配置文件修复字符串