This example describes how the Substr_count () function in PHP gets the number of occurrences of substrings. Share to everyone for your reference, as follows:
Substr_count () in PHP can be used to calculate the number of occurrences of a substring of a specified string.
The Substr_count () function is defined as follows:
Substr_count (String,substring,start,length)
Parameter description:
string is required. Specifies the string to be checked.
substring required. Specifies the string to search for.
Start is optional. Specifies where to start the search in the string.
Length is optional. Specifies the length of the search.
The sample code is as follows:
<?php $str = "This site provides a lot of script code and script effects download"; Echo Substr_count ($str, "script"); echo "
"; Echo Substr_count ($str, "script", 16);//Specify to start searching for Echo after the 16th character "
"; Echo Substr_count ($str, "script", 16,10);//Specifies to search for 10 characters from the 16th character End?>
The results of the operation are as follows:
321
Read more about PHP string operations for more information on this site: PHP string Usage Summary
I hope this article is helpful to you in PHP programming.
The above describes the PHP Substr_count function to get the number of substring occurrences of the method, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.