Usage of substr_count function in php: [substr_count(string,substring,start,length)]. The substr_count function is used to count the number of times a specified string appears in a string.
php The substr_count function is used to count the number of occurrences of a string in another string. Its syntax is substr_count(string,substring,start,length) , the parameter string is required and specifies the string to be checked; substring is required and specifies the string to be searched.
(Recommended tutorial: php video tutorial)
How to use the php substr_count function?
Function: Count the number of occurrences of a string in another string
Syntax:
substr_count(string,substring,start,length)
Parameters:
string required. Specifies the string to be checked.
substring Required. Specifies the string to search for.
start Optional. Specifies where in the string to begin the search.
length Optional. Specifies the length of the search.
Description:
Calculate the number of times a substring appears in a string. Substrings are case-sensitive. This function does not count overlapping substrings. This function generates a warning if the start parameter plus the length parameter is greater than the string length.
php substr_count() function usage example 1
<?php echo substr_count("I love php.I'm study in php.cn","php"); ?>
Output:
2
php substr_count() function usage example 2
<?php $str = "This is php.cn test"; echo substr_count($str,"is",3,9); ?>
Output:
1
The above is the detailed content of How to use the substr_count function in php. For more information, please follow other related articles on the PHP Chinese website!