9

PHP | SplFileObject fgetss() Function

 3 years ago
source link: https://www.geeksforgeeks.org/php-splfileobject-fgetss-function/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
SplFileObject fgetss() Function
Related Articles
PHP | SplFileObject fgetss() Function
  • Last Updated : 19 Dec, 2018

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

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

Output:

Welcome To GeeksforGeeks! Text out of the HTML block.

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK