Skip to content
Related Articles

Related Articles

PHP | SplFileObject fgetss() Function
  • Last Updated : 05 Mar, 2021

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




<?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




<?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: http://php.net/manual/en/splfileobject.fgets.php
 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :