Php/docs/filters.string

提供:Dev Guides
< Php
移動先:案内検索

文字列フィルタ

これらのフィルタは、まさしくその名が示すとおりの働きをし、PHP 組み込み の文字列処理関数と同じように動作します。これらのフィルタについての より詳しい情報は、対応する関数のマニュアルを参照してください。

string.rot13

このフィルタは、すべてのストリームデータに対して 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.   */?>

string.toupper

このフィルタは、すべてのストリームデータに対して 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.   */?>

string.tolower

このフィルタは、すべてのストリームデータに対して 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.   */?>

string.strip_tags

このフィルタは、すべてのストリームデータに対して 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);/* 出力:     <b>bolded text</b> 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);/* 出力:     <b>bolded text</b> enlarged to a level 1 heading   */?>