Filesystem 函数
PHP Manual

fgetss

(PHP 4, PHP 5)

fgetss从文件指针中读取一行并过滤掉 HTML 标记

说明

string fgetss ( resource $handle [, int $length [, string $allowable_tags ]] )

fgets() 相同,只除了 fgetss 尝试从读取的文本中去掉任何 HTML 和 PHP 标记。

可以用可选的第三个参数指定哪些标记不被去掉。

Note:

allowable_tags 是 PHP 3.0.13,PHP 4.0.0 新加的。

参数 length 从 PHP 5 起开始可选。

Note: 在读取在 Macintosh 电脑中或由其创建的文件时, 如果 PHP 不能正确的识别行结束符,启用运行时配置可选项 auto_detect_line_endings 也许可以解决此问题。

参见 fgets()fopen()fsockopen()popen()strip_tags()

参数

handle

文件指针必须是有效的,必须指向由 fopen()fsockopen() 成功打开的文件(并还未由 fclose() 关闭)。

length

Length of the data to be retrieved.

allowable_tags

You can use the optional third parameter to specify tags which should not be stripped.

返回值

Returns a string of up to length - 1 bytes read from the file pointed to by handle, with all HTML and PHP code stripped.

If an error occurs, returns FALSE.

更新日志

版本 说明
5.0.0 The length parameter is optional

Example #1 Reading a PHP file line-by-line

<?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);

$handle = @fopen("sample.php""r");
if (
$handle) {
    while (!
feof($handle)) {
        
$buffer fgetss($handle4096);
        echo 
$buffer;
    }
    
fclose($handle);
}
?>

以上例程的输出类似于:

 Welcome! Today is the  of .

Text outside of the HTML block.

注释

Note: 在读取在 Macintosh 电脑中或由其创建的文件时, 如果 PHP 不能正确的识别行结束符,启用运行时配置可选项 auto_detect_line_endings 也许可以解决此问题。

参见


Filesystem 函数
PHP Manual