PHP fgetss() 函數


PHP Filesystem 參考手冊 完整的 PHP Filesystem 參考手冊

定義和用法

fgetss() 函數從打開的檔中返回一行,並過濾掉 HTML 和 PHP 標籤。

fgetss() 函數會在到達指定長度或讀到檔末尾(EOF)時(以先到者為准),停止返回一個新行。

如果失敗該函數返回 FALSE。

語法

fgetss(file,length,tags)

參數 描述
file 必需。規定要檢查的檔。
length 可選。規定要讀取的位元組數。默認是 1024 位元組。

注意:該參數在 PHP 5 之前的版本是必需的。

tags 可選。指定哪些標記不被去掉。


實例

實例 1

test.html 代碼內容:

<p><b>This is a paragraph.</b></p>

PHP 代碼:

<?php
$file = fopen("test.html","r");
echo fgetss($file);
fclose($file);
?>

上面的代碼將輸出:

This is a paragraph.

實例 2

<?php
$file = fopen("test.html","r");
echo fgetss($file,1024,"<p>,<b>");
fclose($file);
?>

上面的代碼將輸出:

This is a paragraph.

上面輸出的源代碼是:

<p><b>This is a paragraph.</b></p>


PHP Filesystem 參考手冊 完整的 PHP Filesystem 參考手冊