php The strchr function is used to search for the first occurrence of a string in another string. Its syntax is strchr (string, search, before_search). The parameter string is required, which refers to the string to be searched; search is required, Refers to the string that specifies the search.
#php How to use strchr function?
Definition and Usage
strchr() function searches for the first occurrence of a string in another string.
This function is an alias of 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.
Syntax
strchr(string,search,before_search);
Parameters
string Required. Specifies the string to be searched for.
search Required. Specifies the string to search for.
If the parameter is a number, search for characters matching the ASCII value corresponding to the number.
before_search Optional. Boolean value with default value "false"
If set to "true", it will return the portion of the string before the first occurrence of the search parameter.
Return value: Returns the rest of the string (from the matching point). Returns FALSE if the searched string is not found.
PHP version: 4
Change log: In PHP 5.3, the before_search parameter is added.
Example 1
Search a string by the ASCII value of "o" and return the rest of the string:
<?php echo strchr("Hello world!",111); ?>
Output:
o world!
Example 2
Return the string part before the first occurrence of "world":
<?php echo strchr("Hello world!","world",true); ?>
Output:
Hello
Example 3
Find the first occurrence of "world" in "Hello world!" and return the rest of this string:
<?php echo strchr("Hello world!","world"); ?>
Output:
world!
The above is the detailed content of How to use php strchr function?. For more information, please follow other related articles on the PHP Chinese website!