phpday 2027 - Call for Papers

SplFileObject::fgetss

(PHP 5 >= 5.1.0, PHP 7)

SplFileObject::fgetss — ファイルから 1 行取り出し HTML タグを取り除く

警告

この関数は PHP 7.3.0 で 非推奨 になり、PHP 8.0.0 で 削除 されました。この関数に頼らないことを強く推奨します。

説明

public function SplFileObject::fgetss(string $allowable_tags = ?): string

SplFileObject::fgetss() 読み込むテキストから HTML と PHP タグを取り除こうとすること以外、SplFileObject::fgets() と同じです。 この関数は、ある呼び出しから別の呼び出しの間のパースの状態を保持します。 したがって、これは SplFileObject::fgets() の戻り値に対して strip_tags() 関数を呼び出すのと同じではありません。

パラメータ

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.

参考

User Contributed Notes

There are no user contributed notes for this page.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top