Easy Tutorial
❮ Php Ref Curl Func Date Timezone Abbreviations List ❯

PHP strchr() Function

PHP String Reference Manual

Example

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


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 case-insensitive search, use the stristr() function.


Syntax

Parameter 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.
before_search Optional. A boolean value with a default of "false". If set to "true", it returns the part of the string before the first occurrence of the search parameter.

Technical Details

Return Value: Returns the rest of the string (from the matching point). If the search string is not found, it returns FALSE.
PHP Version: 4+
--- ---
Changelog: The before_search parameter was added in PHP 5.3.
--- ---

More Examples

Example 1

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

Example 2

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


PHP String Reference Manual

❮ Php Ref Curl Func Date Timezone Abbreviations List ❯