Description of the function used to find the number of occurrences of a string in php. You can use the substr_count () function to find the number of occurrences of a string in php. I will introduce these functions to you in detail. Substr_count ($ haystack, $ needle [. you can use the substr_count () function to find the number of occurrences of a string in php. next I will introduce these functions in detail.
Substr_count ($ haystack, $ needle [, $ offset [, $ length])
/$ Haystack indicates the parent string, and $ needl indicates the character to be searched
// $ Offset indicates the start point of the search, and $ length indicates the length of the search, all of which are optional parameters.
Instance:
| The code is as follows: |
|
|
$ Str = "this is a test ";
Echo substr_count ($ str, 'is ').'
';
Echo substr_count ($ str, 'is ', 3 ).'
';
Echo substr_count ($ str, 'is ', 3, 3 ).'
';
?> |
Instance:
| The code is as follows: |
|
|
$ Str = 'http: // www.bkjia.com Love program net_getting started with software programming _ Software Design Exchange _ character occurrences ';
Echo substr_count ($ str, 'w ').'
';
Echo substr_count ($ str, 'T ').'
';
Echo substr_count ($ str, 'Love program net ');
?>
Output result:
// The output result is as follows:
3
2
1 |
Then share some string lookup functions
Strstr-first appearance of the search string
Stristr strstr case-insensitive version
Strpos-locate the first occurrence of a string
String substr (string $ string, int $ start [, int $ length])
String strrchr (string $ haystack, mixed $ needle)
Strripos-calculate the position of the last occurrence of the specified string in the target string (case insensitive)
Stripos-locate the first occurrence of a string (no size difference)
Strrpos-calculate the position of the last occurrence of the specified string in the target string
The aggregate () function is implemented. I will introduce these functions to you in detail. Substr_count ($ haystack, $ needle [,...