In PHP, the substr_count () function is used to obtain the number of occurrences of a substring, phpsubstr_count. In PHP, the substr_count () function obtains the number of occurrences of a substring. phpsubstr_count this article describes how to obtain the occurrences of a substring using the substr_count () function in PHP. How to use the substr_count () function in PHP to obtain the occurrence times of a substring, phpsubstr_count
This example describes how to obtain the occurrence times of a substring using the substr_count () function in PHP. We will share this with you for your reference. The details are as follows:
Substr_count () in PHP can be used to calculate the number of times a specified string substring appears.
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 is required. Specifies the string to be searched.
Start is optional. Specifies where to start searching in the string.
Length is optional. Specify the length of the search.
Sample codeAs follows:
<? Php $ str = "($ str," script "); echo"
"; Echo substr_count ($ str," script ", 16); // specify to search for echo after 16th characters"
"; Echo substr_count ($ str," script ", 16th); // specifies that the search will end with 10 characters starting from characters.
The running result is as follows:
321