How to use php strchr function?

藏色散人
Release: 2023-02-22 22:54:01
original
3428 people have browsed it

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

How to use php strchr function?

#php How to use strchr function?

Definition and Usage

strchr() function searches for the first occurrence of a string in another string.

This function is an alias of the strstr() function.

Note: This function is binary safe.

Note: This function is case-sensitive. To perform a case-insensitive search, use the stristr() function.

Syntax

strchr(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. Boolean value with default value "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 rest 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.

Example 1

Search a string by the ASCII value of "o" and return the rest of the string:

Copy after login

Output:

o world!
Copy after login

Example 2

Return the string part 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 this string:

Copy after login

Output:

world!
Copy after login

The above is the detailed content of How to use php strchr 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 [email protected]
Latest issues
Popular Tutorials
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!