The fgetss()
function in PHP is a built-in function. It gets a line from the file while removing all the tags from a line in an open file. These tags may be HTML or PHP tags.
The method fgetss
stops automatically after reaching the specified length, the file reaches its end, or the line ends.
fgetss(file, length, tags)
file
: The filename containing the text and tags being extracted.
length
: Number of bytes that the user wants to read using this function. The default value is 1024
bytes.
tags
: Optional parameter. Using this parameter, a user can define tags that do not need to be removed.
The function returns a string without the tags. However, if the function fails for any reason, it returns False
.
Larger files may take a long time to read, as this method reads one line at a time.
For multiple usages of this method, we must clear the buffer.
On failure, this method may return False
. However, if the function execution fails, it returns False
.
Here is the code for a complete understanding of the fgetss
method.
<?php// opening the file$my_file = fopen("hello.txt", "rw");// removing the tags from first line of the file except the <strong> tagecho fgetss($my_file, 1024, '<strong>');// close the filefclose($my_file);?>
The file hello.txt
is opened and appointed with the file stream my_file
. The fgetss
function is then called to get a maximum of 1024
bytes and such that all tags except the <strong>
HTML tags are removed.
The output then shows characters from only the one line of the file with the <p>
tag removed.
Free Resources