当前位置:网站首页>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如何查询字符串出现位置”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。
边栏推荐
- Alluxio for Presto fu can across the cloud self-service ability
- Xshell命令
- tiup install
- 编译、链接 - 笔记 - 3
- Packages - Notes
- 【云原生】阿里云ARMS业务实时监控
- QIIME2得到PICRUSt2结果后如何分析
- SEATA distributed transaction
- Applicable scenarios of TiDB tools
- [Cloud native] Grayscale release, blue-green release, rolling release, grayscale release explanation
猜你喜欢

动态规划 --- 状态压缩DP 详细解释

nodejs environment variable settings

Excel uses Visual Basic Editor to modify macros

Memory-mapped, bit-band operations
![[Cloud native] Grayscale release, blue-green release, rolling release, grayscale release explanation](/img/90/f7d85ac655d9206fefbd28e0fc81ba.png)
[Cloud native] Grayscale release, blue-green release, rolling release, grayscale release explanation

极验深知v2分析

yarn安装详细教程说明、升级教程、修改yarn的全局和缓存目录、yarn基本命令

Database - SQL

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

Placement Rules 使用文档
随机推荐
元宇宙的前景及四大赛道
GeoServer + openlayers
tiup list
STM32F407定时器输入捕获
TiDB 工具功能概览
【为宏正名】99%的人从第一天学习C语言就自废的武功
TensorFlow custom training function
GeoServer
TiUP 命令概览
tiup clean
Packages - Notes
软件包 - 笔记
《二舅》刷屏了!
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
Local Transactions vs Distributed Transactions
SEATA distributed transaction
面试何惧调优!腾讯技术官私藏的性能优化方案手册,原理实战齐全
【云原生 • DevOps】influxDB、cAdvisor、Grafana 工具使用详解
在树莓派上驱动CSI摄像头
Core Topics under Microservice Architecture (2): Design Principles and Core Topics of Microservice Architecture