The fgetss() function returns a line, with HTML and PHP tags removed, from an open file.
PHP fgetss() Function has the following syntax.
fgetss(file,length,tags)
Parameter | Is Required | Description |
---|---|---|
file | Required. | File to check |
length | Optional. | Number of bytes to read. Default is 1024 bytes. |
tags | Optional. | Tags that will not be removed |
This function returns FALSE on failure.
<?php/*from w ww . j a va 2s .co m*/
$str = <<<EOD
<html><body>
<p>Welcome!.</p>
</body></html>
Text outside of the HTML block.
EOD;
file_put_contents('index.php', $str);
$handle = @fopen("index.php", "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgetss($handle, 1024);
echo $buffer;
}
fclose($handle);
}
?>
The code above generates the following result.
The following code shows how to get 1024 character from a file and keep paragraph and bold tag.
<?php
$file = fopen("test.txt","r");
echo fgetss($file,1024,"<p>,<b>");
fclose($file);
?>
The code above generates the following result.
The following code shows how to get a line, with HTML and PHP tags removed, from an open file.
<?php
$file = fopen("a.php","r");
echo fgetss($file);
fclose($file);
?>