This article describes how to use the substr_count () function in PHP to obtain the occurrence times of a substring, and analyzes the functions, functions, and usage techniques of the substr_count () function based on examples, for more information about how to use the substr_count () function in PHP to obtain the number of occurrences of a substring, see the following example. 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 = "script home provides a large number of script code and special script effects downloads"; echo substr_count ($ 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