php stristr()函数
php stristr()函数是一个用于查找字符串中第一次出现另一个字符串的位置的函数,它是不区分大小写的,也就是说,在查找的过程中不会考虑字符串中字母的大小写。
stristr()函数的语法如下:
string stristr ( string $haystack , mixed $needle [, bool $before_needle = false ] )
haystack参数指定要查找的字符串;needle参数指定要查找的子字符串;before_needle参数指定是否只返回needle之前的字符串,默认为false,即返回needle之后的字符串。
下面通过一个实例来说明stristr()函数的使用:
$str = "Hello World"; echo stristr($str, "world"); //输出 world echo stristr($str, "world", true); //输出 Hello
上面的代码中,我们定义了一个字符串$str,使用stristr()函数查找$str字符串中是否包含“world”,第一次调用stristr()函数时,我们没有指定before_needle参数,所以默认为false,返回的是needle之后的字符串,即“world”;第二次调用stristr()函数时,我们指定before_needle参数为true,返回的是needle之前的字符串,即“Hello”。
:php stristr()函数是一个用于查找字符串中第一次出现另一个字符串的位置的函数,它是不区分大小写的,语法为:string stristr ( string $haystack , mixed $needle [, bool $before_needle = false ] ),haystack参数指定要查找的字符串;needle参数指定要查找的子字符串;before_needle参数指定是否只返回needle之前的字符串,默认为false,即返回needle之后的字符串。