The SplFileObject::fgetss() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to get line from file and strip HTML tags.
Syntax:
string SplFileObject::fgetss( $tags)
Parameters: This function accept only one parameter $tags an optional parameter to specify tags which should not be stripped.
Return values: This function returns the next line of the file with HTML and PHP code stripped return FALSE otherwise.
Below Programs illustrate the SplFileObject::fgetss() function in PHP.
Program 1:
<?php
$gfg = <<<EOD
<html><body>
<h1>Welcome To GeeksforGeeks!</h1>
</body></html>
Text out of the HTML block.
EOD;
file_put_contents("gfg.txt", $gfg);
$file = new SplFileObject("gfg.txt");
while (!$file->eof()) {
echo $file->fgetss();
}
?>
Output:
Welcome To GeeksforGeeks! Text out of the HTML block.
Program 2:
<?php
$gfg = <<<EOD
<html><body>
<h1>Welcome To GeeksforGeeks!</p>
</body></html>
Text out of the HTML block.
EOD;
file_put_contents(__FILE__, $gfg);
$file = new SplFileObject(__FILE__);
while (!$file->eof()) {
echo $file->fgetss();
}
?>
Output:
Welcome To GeeksforGeeks! Text out of the HTML block.
Reference: https://www.php.net/manual/en/splfileobject.fgets.php