Example
Calculate the number of times "world" appears in string:
<?php echo substr_count("Hello world. The world is nice","world"); ?>
substr_count() function counts the number of times a substring appears in a string.
Note: Substrings are case-sensitive.
Note: This function does not count overlapping substrings (see Example 2).
Note: If the start parameter plus the length parameter is greater than the string length, this function generates a warning (see Example 3).
Syntax
substr_count(string,substring,start,length)
Parameters | Description |
string | Required. Specifies the string to check. |
substring | Required. Specifies the string to be retrieved. |
start | Optional. Specifies where in the string to begin the search. |
length | Optional. Specifies the length of the search. |
Technical details
Return value: | Returns the occurrence of the substring in the string frequency. |
PHP Version: | 4+ |
##Update Log : | In PHP 5.1,newly addedstart and length parameters. |