fgestss() 函数从文件指针获取一行并去除 HTML 和 PHP 标签。 fgetss() 函数返回从句柄指向的文件中读取的最大长度为 1 个字节的字符串,其中所有 HTML 和 PHP 代码都被条带化。如果发生错误,则返回 FALSE。
fgetss(file_path,length,tags)
file_pointer - 文件指针必须有效,并且必须指向由 fopen() 成功打开的文件或 fsockopen()(尚未由 fclose() 关闭)。
length - 数据长度
标签 - 您不想删除的标签。
立即学习“PHP免费学习笔记(深入)”;
fgetss() 函数返回从句柄指向的文件中读取的最大长度为 1 个字节的字符串,其中所有 HTML 和 PHP 代码都被条带化。如果发生错误,则返回 FALSE。
假设我们有包含以下内容的“new.html”文件。
<p><strong>Asia</strong> is a <em>continent</em>.</p>
<?php $file_pointer= fopen("new.html", "rw"); echo fgetss($file_pointer); fclose($file_pointer); ?>
以下是输出结果。我们没有添加参数以避免剥离HTML标签,因此输出结果如下:
Asia is a continent.
Now, let us see another example wherein we have the same file, but we will add the length and HTML tags parameters to avoid stripping of those tags.
<?php $file_pointer = @fopen("new.html", "r"); if ($file_pointer) { while (!feof($handle)) { $buffer = fgetss($file_pointer, 1024"<p>,<strong>,<em>"); echo $buffer; } fclose($file_pointer); } ?>
Asia is a continent.
以上就是PHP中的fgetss()函数的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号