大网数据广告活动
PHP 语言与运行手册

SplFileObject::fgetss · Gets line from file and strip HTML tags

· 52CE 我爱测

SplFileObject::fgetss — Gets line from file and strip HTML tags

SplFileObject::fgetss

(PHP 5 >= 5.1.0, PHP 7)

SplFileObject::fgetss — Gets line from file and strip HTML tags

警告

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

说明

public function SplFileObject::fgetss(string $allowable_tags = ?): string

Identical to SplFileObject::fgets(), except that SplFileObject::fgetss() attempts to strip any HTML and PHP tags from the text it reads. 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 SplFileObject::fgets().

参数

allowable_tags

Optional parameter to specify tags which should not be stripped.

返回值

Returns a string containing the next line of the file with HTML and PHP code stripped, or false on error.

示例

示例 #1 SplFileObject::fgetss() example

<?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.

参见

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。