Home  >  Article  >  Backend Development  >  PHP function stripos() to find the first occurrence of a string in another string

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

黄舟
黄舟Original
2017-11-04 10:41:357869browse

Example

Find the first occurrence of "php" in the string:

<?php
echo stripos("I love php, I love php too!","PHP");
?>

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)
Parameters Description
string Required. Specifies the string to be searched for.
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, &#39;a&#39;) == false) {
       //0是a存在与$r总但是由于0和false是相等的,所以就执行了这里
}
if(stripos($r, &#39;a&#39;) === false) {
     // 这种情况我们必须使用全等于才行
}


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!

Statement:
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