PHP strchr function is used to find the first occurrence of a string. Its syntax is [strchr(string,search,before_search)]. The parameter string is required and specifies the string to be searched.
php strchr function usage:
php strchr() function syntax
Function: Searches for the first occurrence of a string within another string.
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 argument is a number, searches for characters that match the ASCII value for that number.
before_search Optional. The default value is a Boolean value of "false". If set to "true", it returns the portion of the string preceding the first occurrence of the search parameter.
Description:
This function is an alias of the strstr() function. This function is binary safe. This function is case-sensitive. To perform a case-insensitive search, use the stristr() function.
php strchr() function usage example 1:
<?php echo strchr("Hello php.cn!","php"); ?>
Output:
php.cn
php strchr() function usage example 2:
<?php echo strchr("i study php in php.cn!","study"); ?>
Output:
study php in php.cn!
This article is an introduction to the PHP strchr function. I hope it will be helpful to friends in need!
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!