PHP | SplFileObject fgetss() Function

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::fgets() function in PHP.

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
}
?>

chevron_right


Output:

Welcome To GeeksforGeeks! Text out of the HTML block.

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
}
?> 

chevron_right


Output:

Welcome To GeeksforGeeks! Text out of the HTML block.

Reference: http://php.net/manual/en/splfileobject.fgets.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.