SplFileObject::fgetss
(PHP 5 >= 5.1.0, PHP 7)
SplFileObject::fgetss — ファイルから 1 行取り出し HTML タグを取り除く
説明
public SplFileObject::fgetss
([ string
$allowable_tags
] ) : stringSplFileObject::fgetss() attempts to strip 読み込むテキストから HTML と PHP タグを取り除こうとすること以外、SplFileObject::fgets() と同じです。
パラメータ
-
allowable_tags -
オプションのパラメータで、取り除きたくないタグを指定します。
返り値
HTML と PHP コードが取り除かれたファイルの次の行を含む文字列、もしくは FALSE を返します。
例
例1 SplFileObject::fgetss() の例
<?php
$str = <<<EOD
<html><body>
<p>Welcome! Today is the <?php echo(date('jS')); ?> of <?= date('F'); ?>.</p>
</body></html>
Text outside of the HTML block.
EOD;
file_put_contents("sample.php", $str);
$file = new SplFileObject("sample.php");
while (!$file->eof()) {
echo $file->fgetss();
}
?>
上の例の出力は、 たとえば以下のようになります。
Welcome! Today is the of . Text outside of the HTML block.
参考
- fgetss() - ファイルポインタから 1 行取り出し、HTML タグを取り除く
- SplFileObject::fgets() - ファイルから 1 行取り出す
- SplFileObject::fgetc() - ファイルから文字を取り出す
- SplFileObject::current() - ファイルの現在の行を取得する