当前位置:网站首页>php如何查询字符串出现位置
php如何查询字符串出现位置
2022-07-30 15:13:00 【亿速云】
php如何查询字符串出现位置
本文小编为大家详细介绍“php如何查询字符串出现位置”,内容详细,步骤清晰,细节处理妥当,希望这篇“php如何查询字符串出现位置”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
4种方法:1、用stripos(),返回第一次出现的位置(不区分大小写),语法“stripos(字符串,查询值)”;2、用strpos(),返回第一次出现的位置(区分大小写),语法“strpos(字符串,查询值)”;3、用strripos(),返回最后一次出现的位置,语法“strripos(字符串,查询值)”;4、用strrpos(),语法“strrpos(字符串,查询值)”。

本教程操作环境:windows7系统、PHP8.1版、DELL G3电脑
方法1:使用stripos()函数
stripos() 函数查找字符串在另一字符串中第一次出现的位置(不区分大小写)。
返回值:返回字符串在另一字符串中第一次出现的位置,如果没有找到字符串则返回 FALSE。注释: 字符串位置从 0 开始,不是从 1 开始。
<?phpheader('content-type:text/html;charset=utf-8'); $str="Hello world!";echo "原字符串:".$str."<br>";$find="world";echo "指定子串world的出现位置:".stripos($str,$find);?>
方法2:使用strpos()函数
strpos() 函数查找字符串在另一字符串中第一次出现的位置(区分大小写)。
返回值:返回字符串在另一字符串中第一次出现的位置,如果没有找到字符串则返回 FALSE。
<?phpheader('content-type:text/html;charset=utf-8'); $str="I love php, I love php too!";echo "原字符串:".$str."<br>";$find1="php";echo "指定子串php的出现位置:".strpos($str,$find1)."<br>";$find2="PHP";echo "指定子串PHP的出现位置:".strpos($str,$find2);?>
方法3:使用strripos()函数
strripos() 函数查找字符串在另一字符串中最后一次出现的位置(不区分大小写)。
返回值:返回字符串在另一字符串中最后一次出现的位置,如果没有找到字符串则返回 FALSE。
<?phpheader('content-type:text/html;charset=utf-8'); $str="I love php, I love php too!";echo "原字符串:".$str."<br>";$find1="php";echo "指定子串php的出现位置:".strripos($str,$find1)."<br>";$find2="PHP";echo "指定子串PHP的出现位置:".strripos($str,$find2);?>
方法4:使用strrpos()函数
strrpos() 函数查找字符串在另一字符串中最后一次出现的位置(区分大小写)。
返回值:返回字符串在另一字符串中最后一次出现的位置,如果没有找到字符串则返回 FALSE。
<?phpheader('content-type:text/html;charset=utf-8'); $str="I love php, I love php too!";echo "原字符串:".$str."<br>";$find1="php";echo "指定子串php的出现位置:".strrpos($str,$find1)."<br>";$find2="PHP";echo "指定子串PHP的出现位置:".strrpos($str,$find2);?>
读到这里,这篇“php如何查询字符串出现位置”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。
边栏推荐
猜你喜欢

Mysql database query is very slow. Besides the index, what else can be caused?

Delayed message queue

定时任务 corn

【云原生 • DevOps】influxDB、cAdvisor、Grafana 工具使用详解

ISELED---氛围灯方案的新选择

golang modules初始化项目
![[Cloud native] Alibaba Cloud ARMS business real-time monitoring](/img/e7/55f560196521d22f830b2caf110e34.png)
[Cloud native] Alibaba Cloud ARMS business real-time monitoring

Alluxio为Presto赋能跨云的自助服务能力

Sparse-PointNet: See Further in Autonomous Vehicles 论文笔记
![[Cloud Native] Service Industry Case - Solutions for Unpredictable Concurrency Scenarios](/img/c7/3faa29dc374e2e16e59ac9b8ebf249.png)
[Cloud Native] Service Industry Case - Solutions for Unpredictable Concurrency Scenarios
随机推荐
The Prospects of the Metaverse and the Four Tracks
数据库-SQL
如何做好技术选型
Introduction to kasini3000
FME读写cass数据的方案及操作流程
yarn安装详细教程说明、升级教程、修改yarn的全局和缓存目录、yarn基本命令
nodejs environment variable settings
TiDB tool download
tiup help
Placement Rules 使用文档
How to split microservices?
websocket flv 客户端解封包
HTTP缓存小结
SEATA distributed transaction
Excel使用Visual Basic Editor对宏进行修改
Back waves are coming!Ali produced the "second generation" container technical manual and brain map, which is too fragrant
yarn的安装及使用教程
golang modules initialization project
Debug - Notes
GeoServer