Home > Backend Development > PHP Tutorial > 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

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

Example

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

<?php
echo stripos("I love php, I love php too!","PHP");
?>
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
ParametersDescription
stringRequired. Specifies the string to be searched for.
findRequired. Specifies the characters to search for.
startOptional. 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) {
     // 这种情况我们必须使用全等于才行
}
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:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template