I recommend using the solution by rchillet for <PHP5
michiels solution is quite slow if you use it for long strings or call it many times.
stripos
説明
int stripos ( string haystack, string needle [, int offset] )文字列 haystack の中で needle が最初に現れる位置を数字で返します。 strpos() と異なり、stripos() は大文字小文字を区別しません。
needle は、ひとつまたは複数の文字であることに 注意しましょう。
needle がみつからない場合、 strpos() は boolean FALSE を返します。
| 警告 |
この関数は論理値 FALSE を返す可能性がありますが、FALSE として評価される 0 や "" といった値を返す可能性もあります。 詳細については 論理値の セクションを参照してください。この関数の返り値を調べるには ===演算子 を 使用してください。 |
needle が文字列でない場合、それは整数に 変換され、文字列中の位置として扱われます。
オプションのパラメータ offset により、 検索を開始する haystack の位置を指定することが できます。この場合でも返される位置は、 haystack の先頭からの位置のままとなります。
注意: この関数はバイナリデータに対応しています。
strpos()、strrpos()、 strrchr()、substr()、 stristr()、strstr()、 strripos() および str_ireplace() も参照ください。
stripos
dazzle
16-Aug-2006 11:20
16-Aug-2006 11:20
michiel at mb-it dot nl
10-Jul-2006 08:03
10-Jul-2006 08:03
Since the stripos-function is PHP5-only, the function below could give PHP4-users the same functionallity:
function stripos($string,$word)
{
$retval = false;
for($i=0;$i<=strlen($string);$i++)
{
if (strtolower(substr($string,$i,strlen($word))) == strtolower($word))
{
$retval = true;
}
}
return $retval;
}
rchillet at hotmail dot com
28-Apr-2006 05:45
28-Apr-2006 05:45
improvement the function of heavyraptor with int offset parametre.
if (!function_exists("stripos")) {
function stripos($str,$needle,$offset=0)
{
return strpos(strtolower($str),strtolower($needle),$offset);
}
}
heavyraptor
21-Mar-2006 11:59
21-Mar-2006 11:59
If you're using PHP < 5, you can use this alternate function, same thing like stripos:
<?php
if (!function_exists("stripos")) {
function stripos($str,$needle) {
return strpos(strtolower($str),strtolower($needle));
}
}
?>
Such a logical function but I hope it helps ...
sim
03-Oct-2004 02:17
03-Oct-2004 02:17
Just to be explicit, the position index returned by strpos starts at 0, not 1. e.g. strpos('abc','a') returns 0.
aidan at php dot net
31-May-2004 02:36
31-May-2004 02:36
This functionality is now implemented in the PEAR package PHP_Compat.
More information about using this function without upgrading your version of PHP can be found on the below link:
http://pear.php.net/package/PHP_Compat