array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'filters.string.php', 1 => '文字列フィルタ', ), 'up' => array ( 0 => 'filters.php', 1 => '利用できるフィルタのリスト', ), 'prev' => array ( 0 => 'filters.php', 1 => '利用できるフィルタのリスト', ), 'next' => array ( 0 => 'filters.convert.php', 1 => '変換フィルタ', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'appendices/filters.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
これらのフィルタは、まさしくその名が示すとおりの働きをし、PHP 組み込み の文字列処理関数と同じように動作します。これらのフィルタについての より詳しい情報は、対応する関数のマニュアルを参照ください。
このフィルタは、すべてのストリームデータに対して str_rot13() 関数を適用するのと同じ動作をします。
例1 string.rot13
<?php
$fp = fopen('php://output', 'w');
stream_filter_append($fp, 'string.rot13');
fwrite($fp, "This is a test.\n");
/* 出力: Guvf vf n grfg. */
?>
このフィルタは、すべてのストリームデータに対して strtoupper() 関数を適用するのと同じ動作をします。
例2 string.toupper
<?php
$fp = fopen('php://output', 'w');
stream_filter_append($fp, 'string.toupper');
fwrite($fp, "This is a test.\n");
/* 出力: THIS IS A TEST. */
?>
このフィルタは、すべてのストリームデータに対して strtolower() 関数を適用するのと同じ動作をします。
例3 string.tolower
<?php
$fp = fopen('php://output', 'w');
stream_filter_append($fp, 'string.tolower');
fwrite($fp, "This is a test.\n");
/* 出力: this is a test. */
?>
このフィルタは、すべてのストリームデータに対して strip_tags() 関数を適用するのと同じ動作をします。 以下の2つのうちどちらかの形式でパラメータを渡すことができます。 ひとつは、strip_tags() 関数の第2パラメータと同じ 形式でタグを並べた文字列、もうひとつはタグ名の配列です。
この機能は PHP 7.3.0 で 非推奨になります。この機能に頼らないことを強く推奨します。
例4 string.strip_tags
<?php
$fp = fopen('php://output', 'w');
stream_filter_append($fp, 'string.strip_tags', STREAM_FILTER_WRITE, "<b><i><u>");
fwrite($fp, "<b>bolded text</b> enlarged to a <h1>level 1 heading</h1>\n");
fclose($fp);
/* 出力: bolded text enlarged to a level 1 heading */
$fp = fopen('php://output', 'w');
stream_filter_append($fp, 'string.strip_tags', STREAM_FILTER_WRITE, array('b','i','u'));
fwrite($fp, "<b>bolded text</b> enlarged to a <h1>level 1 heading</h1>\n");
fclose($fp);
/* 出力: bolded text enlarged to a level 1 heading */
?>