How to use php stristr function?

藏色散人
Release: 2023-02-22 22:56:01
Original
3631 people have browsed it

php The stristr function is used to search for the first occurrence of a string in another string. Its syntax is stristr(string,search,before_search). The parameter string is required and specifies the string to be searched; search is required and specifies The string to search for.

How to use php stristr function?

#php How to use stristr function?

Definition and Usage

stristr() function searches for the first occurrence of a string within another string.

Note: This function is binary safe.

Note: This function is not case sensitive. For case-sensitive searches, use the strstr() function.

Syntax

stristr(string,search,before_search)
Copy after login

Parameters

string Required. Specifies the string to be searched for.

search Required. Specifies the string to search for.

If the parameter is a number, search for characters matching the ASCII value corresponding to the number.

before_search Optional. The default value is a Boolean value of "false".

If set to "true", it will return the portion of the string before the first occurrence of the search parameter.

Return value: Returns the remaining part of the string (from the matching point). Returns FALSE if the searched string is not found.

PHP version: 4

Change log:

In PHP 5.3, the before_search parameter is added.

In PHP 4.3, this function becomes binary safe.

Example 1

Search for a string with the ASCII value of "o" and return the remainder of the string:

Copy after login

Output:

o world!
Copy after login

Example 2

Return the part of the string before the first occurrence of "world":

Copy after login

Output:

Hello
Copy after login

Example 3

Find the first occurrence of "world" in "Hello world!" and return the rest of the string:

Copy after login

Output:

world!
Copy after login

The above is the detailed content of How to use php stristr function?. 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!