当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
转换OTU表和序列文件为PICRUST2需要的格式
100w的数据表比1000w的数据表查询更快吗?
Database - SQL
MySql 和 PostgreSQL 数据库 根据一张表update另一张表数据
481-82(105、24、82、34、153)
STM32F407定时器输入捕获
【HMS core】【Media】【Video Editing Service】 The online material cannot be displayed, it is always in the loading state or the network is abnormal
Core Topics under Microservice Architecture (2): Design Principles and Core Topics of Microservice Architecture
FME实现CAD带属性转SHP数据方法
后浪来袭!阿里产出“第二代”容器技术手册及脑图,这也太香了吧
FME realizes the method of converting CAD with attribute to SHP data
Extremely Knowing v2 Analysis
golang modules initialization project
tiup install
70 lines of code, a desktop automatic translation artifact
tiup help
ISELED---the new choice of ambient lighting scheme
[Developers must see] [push kit] Collection of typical problems of push service 2
【HMS core】【FAQ】push kit、WisePlay DRM、Location Kit、Health Kit、3D Modeling Kit、SignPal Kit典型问题合集4
Changing SELECT...FROM to FROM...SELECT doesn't 'fix' SQL