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.
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
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
Returns the string part before the first occurrence of "world":
<?php echo strchr ( "Hello world!" , "world" , true ) ; ?>
Try it yourself
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. |