fgetss() function in PHP

WBOY
Release: 2023-08-29 13:18:01
forward
1201 people have browsed it

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)
Copy after login

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>
Copy after login

Example

is:

Example

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

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.
Copy after login
Copy after login

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

Output

Asia is a continent.
Copy after login
Copy after login

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

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!