PHP stristr()関数
例
「Helloworld!」内で最初に出現する「world」を見つけて、残りの文字列を返します。
<?php
echo stristr("Hello world!","WORLD");
?>
定義と使用法
stristr()関数は、別の文字列内で最初に出現する文字列を検索します。
注:この関数はバイナリセーフです。
注:この関数では大文字と小文字は区別されません。大文字と小文字を区別する検索には、strstr()関数を使用します。
構文
stristr(string,search,before_search)
パラメータ値
Parameter | Description |
---|---|
string | Required. Specifies the string to search |
search | Required. Specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number |
before_search | Optional. A boolean value whose default is "false". If set to "true", it returns the part of the string before the first occurrence of the search parameter. |
技術的な詳細
戻り値: | 残りの文字列(一致点から)を返します。検索する文字列が見つからない場合はFALSEを返します。 |
---|---|
PHPバージョン: | 4歳以上 |
変更ログ: | before_searchパラメーターはPHP5.3で追加されました。 この関数は、PHP4.3でバイナリセーフになりました。 |
その他の例
例
文字列で「o」のASCII値を検索し、残りの文字列を返します。
<?php
echo stristr("Hello world!",111);
?>
例
「world」が最初に出現する前の文字列の部分を返します。
<?php
echo stristr("Hello world!","WORLD",true);
?>
❮PHP文字列リファレンス