PHP function stripos() to find the first occurrence of a string in another string

黄舟
Release: 2023-03-17 06:30:02
Original
7841 people have browsed it

Example

Find the first occurrence of "php" in thestring:

Copy after login

Definition and usage

stripos() Function finds the first occurrence of a string within another string (case-insensitive).

Note: The stripos() function is not case-sensitive.

Note: This function is binary safe.

Related functions:

  • strripos() - Find the last occurrence of a string in another string (case-insensitive )

  • strpos() - Find the first occurrence of a string in another string (case sensitive)

  • strrpos() - Find the last occurrence of a string in another string (case sensitive)

Syntax

stripos(string,find,start)
Copy after login
Parameters Description
string Required. Specifies the string to besearchedfor.
find Required. Specifies the characters to search for.
start Optional. Specifies the location from which to start the search.

Technical details

Return value: Returns a string within another string The position of the first occurrence, or FALSE if the string is not found. Note: String positions start from 0, not 1.
PHP Version: 5+
##Tips and Notes

Note: This function has Writing is insensitive. For case-sensitive searches, use the strpos() function.
Since this function returns the position of the first occurrence of the returned string in another string. So this position may be 0
Then you need to pay attention when the return value is 0

if(stripos($r, 'a') == false) { //0是a存在与$r总但是由于0和false是相等的,所以就执行了这里 } if(stripos($r, 'a') === false) { // 这种情况我们必须使用全等于才行 }
Copy after login


The above is the detailed content of PHP function stripos() to find the first occurrence of a string in another string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!