当前位置:网站首页>php how to query string occurrence position
php how to query string occurrence position
2022-07-30 15:56:00 【Million speed cloud】
How does php query where the string appears
This article will introduce "how to query the location of strings in php" in detail. The content is detailed, the steps are clear, and the details are handled properly. I hope this article "How to query the location of strings in php" can helpLet’s solve your doubts, follow the ideas of the editor to slowly deepen, and let’s learn new knowledge together.
4 methods: 1. Use stripos() to return the position of the first occurrence (case-insensitive), syntax "stripos(string, query value)"; 2. Use strpos() to return the first occurrenceThe position of the second occurrence (case sensitive), the syntax "strpos(string, query value)"; 3. Use strripos() to return the position of the last occurrence, the syntax "strpos(string, query value)"; 4.With strrpos(), the syntax "strrpos(string, query value)".

The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer
Method 1: Use the stripos() function
Thestripos() function finds the first occurrence of a string within another string (case-insensitive).
Return value: Returns the position of the first occurrence of the string in another string, or FALSE if the string is not found.Note: String positions start at 0, not 1.
";$find="world";echo "Specify where the substring world appears: ".stripos($str,$find);?>

Method 2: Use the strpos() function
Thestrpos() function finds the first occurrence of a string within another string (case-sensitive).
Return value: Returns the position of the first occurrence of the string in another string, or FALSE if the string is not found.
";$find1="php";echo "Specify where the substring php appears: ".strpos($str,$find1)."
";$find2="PHP";echo "Specify where the substring PHP appears: ".strpos($str,$find2);?>

Method 3: Use the strripos() function
Thestrripos() function finds the last occurrence of a string within another string (case-insensitive).
Return value: Returns the position of the last occurrence of the string in another string, or FALSE if the string is not found.
";$find1="php";echo "Specify where the substring php appears: ".strripos($str,$find1)."
";$find2="PHP";echo "Specify where the substring PHP appears: ".strripos($str,$find2);?>

Method 4: Use the strrpos() function
Thestrrpos() function finds the last occurrence of a string within another string (case-sensitive).
Return value: Returns the position of the last occurrence of the string in another string, or FALSE if the string is not found.
";$find1="php";echo "Specify where the substring php appears: ".strrpos($str,$find1)."
";$find2="PHP";echo "Specify where the substring PHP appears: ".strrpos($str,$find2);?>

After reading this, the article "How to Query the Appearance of Strings in PHP" has been introduced. If you want to master the knowledge points of this article, you need to use your own hands to understand it. If you want toFor more related articles, please pay attention to the Yisu Cloud Industry Information Channel.
边栏推荐
猜你喜欢

Excel uses Visual Basic Editor to modify macros

经典实例分割模型Mask RCNN原理与测试

【HMS core】【FAQ】push kit、AR Engine、广告服务、扫描服务典型问题合集2

RobotStudio实现喷漆、打磨等功能(曲面路径生成与仿真)

Flask introductory learning tutorial

【C语言】指针和数组的深入理解(第二期)

70 lines of code, a desktop automatic translation artifact

谷歌工程师『代码补全』工具;『Transformers NLP』随书代码;FastAPI开发模板;PyTorch模型加速工具;前沿论文 | ShowMeAI资讯日报

Example of video switching playback (video switching example) code

影像信息提取DEM
随机推荐
Example of video switching playback (video switching example) code
动态规划 --- 状态压缩DP 详细解释
针对 MySQL/InnoDB 刷盘调优
php如何查询字符串出现位置
RISC-V calling conventions
[AGC] Quality Service 1 - Example of Crash Service
tiup env
【C语言】指针和数组的深入理解(第二期)
481-82(105、24、82、34、153)
TiUP 术语及核心概念
哨兵
被捧上天的Scrum敏捷管理为何不受大厂欢迎了?
FME读写cass数据的方案及操作流程
影像信息提取DEM
Packages - Notes
近段时间的学习碎片整理(24)
【重磅来袭】教你如何在RGBD三维重建中获取高质量模型纹理
tiup clean
【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常
武汉星起航:海外仓基础建设成为跨境电商企业的一大出海利器