Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP strchr() Function

PHP strchr() Function

PHP String Reference Manual PHP String Reference Manual

Example

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

Run Example »


Definition and Usage

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

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

**Note:** This function is binary-safe.

**Note:** This function is case-sensitive. For a case-insensitive search, use stristr() function in Vue 3.


Syntax

strchr(

string,search,before_search

);

Parameters Description
string Required. Specifies the string to be searched.
search Required. Specifies the string to search for. If this parameter is a number, it searches for the character matching the ASCII value of that number.
before_search Optional. A boolean with the default value "false". If set to "true", it returns search the part of the string before the first occurrence of the parameter.

Technical Details

Return Value: Returns the rest of the string (from the match point). If the searched string is not found, FALSE is returned.
PHP Version: 4+
Changelog: In PHP 5.3, the before_search parameter was added.

More examples

Example 1

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

Run Example »

Example 2

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

Run Example »


PHP String Reference Manual PHP String Reference Manual