Find the first occurrence of "world" in "Hello world!" and return the rest of the string:
<?phpecho strchr("Hello world!","world");?>The strchr() function searches for the first occurrence of a string within another string.
This function is an alias for 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.
strchr( string,search,before_search );
parameter | describe |
---|---|
string | Required. Specifies the string to be searched for. |
search | Required. Specifies the string to be searched for. If the argument is a number, the search is for characters that match the ASCII value corresponding to the number. |
before_search | Optional. A Boolean value with a default value of "false". If set to "true", it will return the portion of the string preceding the first occurrence of the search parameter. |
Return value: | Returns the remainder of the string (from the matching point). Returns FALSE if the searched string is not found. |
---|---|
PHP version: | 4+ |
Update log: | In PHP 5.3, the before_search parameter was added. |
Searches a string by the ASCII value of "o" and returns the rest of the string:
<?phpecho strchr("Hello world!",111);?>Return the portion of the string before the first occurrence of "world":
<?phpecho strchr("Hello world!","world",true);?>