PHP中的fgetss()函數

WBOY
發布: 2023-08-29 13:18:01
轉載
1202 人瀏覽過

PHP中的fgetss()函數

fgestss() 函數從檔案指標取得一行並移除 HTML 和 PHP 標籤。 fgetss() 函數傳回從句柄指向的檔案中讀取的最大長度為 1 個位元組的字串,其中所有 HTML 和 PHP 程式碼都被條帶化。如果發生錯誤,則傳回 FALSE。

語法

fgetss(file_path,length,tags)
登入後複製

參數

  • #file_pointer - 檔案指標必須有效,並且必須指向由fopen() 成功開啟的檔案或fsockopen()(尚未由fclose() 關閉)。

  • length - 資料長度

  • 標籤 - 您不想刪除的標籤。

傳回

fgetss() 函數傳回從句柄指向的檔案中讀取的最大長度為1 個位元組的字串,其中所有HTML 和PHP 程式碼都被條帶化。如果發生錯誤,則傳回 FALSE。

假設我們有包含以下內容的「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.
登入後複製
登入後複製

以上是PHP中的fgetss()函數的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!