(PHP 5 >= 5.1.0, PHP 7)
SplFileObject::fgetss — 從檔案取得一行並去除 HTML 標籤
此函式自 PHP 7.3.0 起已被 *棄用*,並自 PHP 8.0.0 起已被 *移除*。強烈建議不要依賴此函式。
與 SplFileObject::fgets() 相同,不同之處在於 SplFileObject::fgetss() 會嘗試從讀取的文字中移除任何 HTML 和 PHP 標籤。此函式會在每次呼叫之間保留解析狀態,因此不等同於對 SplFileObject::fgets() 的傳回值呼叫 strip_tags()。
allowable_tags
可選參數,用於指定不應移除的標籤。
傳回一個字串,其中包含檔案的下一行,已移除 HTML 和 PHP 程式碼,錯誤時則傳回 false
。
範例 #1 SplFileObject::fgetss() 範例
<?php
$str = <<<EOD
<html><body>
<p>Welcome! Today is the <?php echo(date('jS')); ?> of <?= date('F'); ?>.</p>
</body></html>
Text outside of the HTML block.
EOD;
file_put_contents("sample.php", $str);
$file = new SplFileObject("sample.php");
while (!$file->eof()) {
echo $file->fgetss();
}
?>
上述範例的輸出結果類似於:
Welcome! Today is the of . Text outside of the HTML block.