Home >Backend Development >PHP Tutorial >fgetss() function in PHP

fgetss() function in PHP

WBOY
WBOYforward
2023-08-29 13:17:061241browse

fgetss() function in PHP

fgestss() function gets a line from the file pointer and strips HTML and PHP tags. The fgetss() function returns a string of maximum length 1 byte read from the file pointed to by the handle, with all HTML and PHP code striped. If an error occurs, returns FALSE.

Syntax

fgetss(file_path,length,tags)

Parameters

  • file_pointer - The file pointer must be valid and must point to the file opened successfully by fopen() File or fsockopen() (not yet closed by fclose()).

  • length - Data length

  • Tags - Tags you do not want to delete.

Return

The fgetss() function returns a string of maximum length 1 byte read from the file pointed to by the handle, in which all HTML and PHP code All are striped. If an error occurs, returns FALSE.

Suppose we have a "new.html" file with the following content. The Chinese translation of

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

Example

is:

Example

<?php
   $file_pointer= fopen("new.html", "rw");
   echo fgetss($file_pointer);
   fclose($file_pointer);
?>

The following is the output result. We didn't add parameters to avoid stripping HTML tags, so the output looks like this:

Output

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. The Chinese translation of

Example

is:

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);
   }
?>

Output

Asia is a continent.

The above is the detailed content of fgetss() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete