PHP Conference Japan 2024

tidy::repairFile

tidy_repair_file

(PHP 5, PHP 7, PHP 8, PECL tidy >= 0.7.0)

tidy::repairFile -- tidy_repair_file修復檔案並將其以字串形式返回

描述

物件導向風格

public static tidy::repairFile(
    string $filename,
    array|string|null $config = null,
    ?string $encoding = null,
    bool $useIncludePath = false
): string|false

程序風格

tidy_repair_file(
    string $filename,
    array|string|null $config = null,
    ?string $encoding = null,
    bool $useIncludePath = false
): string|false

修復給定的檔案並以字串形式返回。

參數

filename

要修復的檔案。

config

參數 config 可以傳遞為陣列或字串。如果傳遞字串,則將其解釋為配置檔案的名稱;否則,將其解釋為選項本身。

請查看 http://tidy.sourceforge.net/docs/quickref.html 以取得每個選項的說明。

encoding

參數 encoding 設定輸入/輸出文件的編碼。編碼的可能值為:asciilatin0latin1rawutf8iso2022macwin1252ibm858utf16utf16leutf16bebig5shiftjis

useIncludePath

include_path 中搜尋該檔案。

返回值

以字串形式返回修復後的內容,如果失敗則返回 false

更新日誌

版本 描述
8.0.0 tidy::repairFile() 現在是一個靜態方法。
8.0.0 configencoding 現在可為 null。

範例

範例 #1 tidy::repairFile() 範例

<?php
$file
= 'file.html';

$tidy = new tidy();
$repaired = $tidy->repairfile($file);
rename($file, $file . '.bak');

file_put_contents($file, $repaired);
?>

參見

新增筆記

使用者貢獻的筆記

此頁面沒有使用者貢獻的筆記。
To Top