卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章16655本站已运行3320

PHP中的fgetss()函数

PHP中的fgetss()函数</p><p>fgestss() 函数从文件指针获取一行并去除 HTML 和 PHP 标签。 fgetss() 函数返回从句柄指向的文件中读取的最大长度为 1 个字节的字符串,其中所有 HTML 和 PHP 代码都被条带化。如果发生错误,则返回 FALSE。

语法

fgetss(file_path,length,tags)

参数

  • file_pointer - 文件指针必须有效,并且必须指向由 fopen() 成功打开的文件或 fsockopen()(尚未由 fclose() 关闭)。

  • length - 数据长度

  • 标签 - 您不想删除的标签。

返回

fgetss() 函数返回从句柄指向的文件中读取的最大长度为 1 个字节的字符串,其中所有 HTML 和 PHP 代码都被条带化。如果发生错误,则返回 FALSE。</p><p>假设我们有包含以下内容的“new.html”文件。

<p><strong>Asia</strong> is a <em>continent</em>.</p>

Example

的中文翻译为:

示例

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

Example

的中文翻译为:

示例

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

卓越飞翔博客
上一篇: C++程序将int变量转换为double
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏