int stripos ( string $haystack , string $needle [, int $offset = 0 ] )
参数说明如下:<?php $findme = 'c'; $mystring1 = 'xyz'; $mystring2 = 'ABC'; $pos1 = stripos($mystring1, $findme); $pos2 = stripos($mystring2, $findme); var_dump($pos1); var_dump($pos2); ?>执行结果为:
bool(false) int(2)
mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
strpos() 和 strrpos()、strripos() 不一样,strpos 的偏移量不能是负数。<?php $findme = 'c'; $findme1 = 'C'; $mystring = 'ABCabc'; $pos1 = strpos($mystring, $findme); $pos2 = strpos($mystring, $findme1); var_dump($pos1); var_dump($pos2); ?>上述代码的执行结果为:
int(5)int(2)
int strripos ( string $haystack , string $needle [, int $offset = 0 ] )
负数偏移量将使得查找从字符串的起始位置开始,到 offset 位置为止。<?php $findme = 'c'; $findme1 = 'C'; $mystring = 'ABCabcabcABC'; $pos1 = strripos($mystring, $findme); $pos2 = strripos($mystring, $findme1); var_dump($pos1); var_dump($pos2); ?>上述代码的执行结果为:
int(11)int(11)
int strrpos ( string $haystack , string $needle [, int $offset = 0 ] )
如果是负数的偏移量,将会导致查找在字符串结尾处开始的计数位置处结束。<?php $findme = 'c'; $findme1 = 'C'; $mystring = 'ABCabcabcABC'; $pos1 = strrpos($mystring, $findme); $pos2 = strrpos($mystring, $findme1); $pos3 = strrpos($mystring, $findme1,-5); var_dump($pos1); var_dump($pos2); var_dump($pos3); ?>上述代码的执行结果为:
int(8)int(11)int(2)
本文链接:http://task.lmcjl.com/news/15904.html