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.
fgetss(file_path,length,tags)
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.
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>
<?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:
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
<?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.
The above is the detailed content of fgetss() function in PHP. For more information, please follow other related articles on the PHP Chinese website!