Thanks to visit codestin.com
Credit goes to www.php.net

update page now

fgetss

(PHP 4, PHP 5, PHP 7)

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

警告

本函数已自 PHP 7.3.0 起弃用,自 PHP 8.0.0 起移除。强烈建议不要依赖本函数。

说明

fgetss(resource $handle, int $length = ?, string $allowable_tags = ?): string

fgets() 相同,只除了 fgetss() 尝试从读取的文本中去掉任何 HTML 和 PHP 标记。 The function retains the parsing state from call to call, and as such is not equivalent to calling strip_tags() on the return value of fgets().

参数

handle

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

length

取回该长度的数据。

allowable_tags

可以用可选的第三个参数指定哪些标记不被去掉。 See strip_tags() for details regarding allowable_tags.

返回值

handle 指向的文件中大读取 length - 1 个字节的字符,并过滤了所有的 HTML 和 PHP 代码。

错误发生时返回 false

示例

示例 #1 一行行读取一个 PHP 文件

<?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($handle, 4096);
echo
$buffer;
}
fclose($handle);
}
?>

以上示例的输出类似于:

Welcome! Today is the  of .

Text outside of the HTML block.

注释

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

参见

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top