php中字符串查询函数是什么
- 建站笔记
- 2022-05-24
- 624
php字符串查询函数是:1、stripos()函数,可查找指定字符的首次出现位置;2、strpos()函数,可查找指定字符的首次出现位置;3、strripos()函数,可查找指定字符最后一次出现的位置;4、strrpos()函数。
本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
php中字符串查询函数
1、stripos()函数
stripos() 用来查找字符串中某部分字符串首次出现的位置(不区分大小写)。
<?php $findme = 'c'; $mystring1 = 'xyz'; $mystring2 = 'ABC'; $pos1 = stripos($mystring1, $findme); $pos2 = stripos($mystring2, $findme); var_dump($pos1); var_dump($pos2); ?>
2、strpos()函数
strpos() 用来查找字符串首次出现的位置(区分大小写)。
<?php $findme = 'c'; $findme1 = 'C'; $mystring = 'ABCabc'; $pos1 = strpos($mystring, $findme); $pos2 = strpos($mystring, $findme1); var_dump($pos1); var_dump($pos2); ?>
3、strripos()函数
strripos() 用来计算指定字符串在目标字符串中最后一次出现的位置(不区分大小写)。
<?php $findme = 'c'; $findme1 = 'C'; $mystring = 'ABCabcabcABC'; $pos1 = strripos($mystring, $findme); $pos2 = strripos($mystring, $findme1); var_dump($pos1); var_dump($pos2); ?>
4、strrpos()函数
strrpos() 用来计算指定字符串在目标字符串中最后一次出现的位置
<?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); ?>
本文由白琉璃于2022-05-24发表在白琉璃源码网,如有侵权或疑问,请联系我们,谢谢。
本文链接:https://www.bailiuli.com/t/1799.html
上一篇
php怎么替换链接地址
下一篇
php如何实现缓存类代码
发表评论