stripos
(PHP 5)
stripos --
大文字/小文字を区別せずに文字列が最初に現れる位置を探す
説明
int
stripos ( string haystack, string needle [, int offset])
文字列haystackの中で
needleが最初に現れる位置を数字で返します。
strpos()と異なり、stripos()
は大文字/小文字を区別しません。そして、strrpos()
と異なり、この関数はパラメータneedleとして
完全な文字列をとることができ、文字列全体が使用されます。
needleがみつからない場合、
strpos() はboolean FALSE
を返します。
警告 |
この関数は論理値
FALSEを返す可能性がありますが、FALSEとして評価される
0や""といった値を返す可能性もあります。
詳細については論理値の
章を参照してください。この関数の返り値を調べるには
===演算子を
使用して下さい。 |
例 1. stripos()の例
<?php $findme = 'a'; $mystring1 = 'xyz'; $mystring2 = 'ABC';
$pos1 = stripos($mystring1, $findme); $pos2 = stripos($mystring2, $findme);
// Nope, 'a' is certainly not in 'xyz' if ($pos1 === false) { echo "The string '$findme' was not found in the string '$mystring1'"; }
// Note our use of ===. Simply == would not work as expected // because the position of 'a' is the 0th (first) character. if ($pos2 !== false) { echo "We found '$findme' in '$mystring2' at position $pos2"; } ?>
|
|
needleが文字列でない場合、
整数に変換され、文字が連続する値として適用されます。
オプションのパラメータoffsetにより、
検索を開始するhaystackの文字を指定することが
できます。この場合でも返される位置は、
haystackの先頭からの位置のままとなります。
strpos(), strrpos(),
strrchr(), substr(),
stristr(), strstr(),
stri_replace()も参照して下さい。