Current Location: Home> Function Categories> strchr

strchr

Alias ​​of strstr
Name:strchr
Category:String
Programming Language:php
One-line Description:Find the first occurrence of a string in another string. (Alias ​​for strstr().)

Definition and usage

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

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

Note: This function is binary safe.

Note: This function is case sensitive. For case-insensitive searches, use stristr() function.

Example

Example 1

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

 <?php
echo strchr ( "Hello world!" , "world" ) ;
?>

Try it yourself

Example 2

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

 <?php
echo strchr ( "Hello world!" , 111 ) ;
?>

Try it yourself

Example 3

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

 <?php
echo strchr ( "Hello world!" , "world" , true ) ;
?>

Try it yourself

grammar

 strchr ( string , search , before_search ) ;
parameter describe
string Required. Specifies the string being searched.
Search

Required. Specifies the string searched.

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 returns the string part before the search parameter first appears.

Similar Functions