php substr_count() function


  Translation results:

UK[kaʊnt] US[kaʊnt]

n.Total number; count; charges; argument

v. Count; calculate the total; count...; important

Third person singular: counts Plural: counts Present participle: counting Past tense: counted Past participle: counted

php substr_count() functionsyntax

Function:Count the number of times a string appears in another string

Syntax: substr_count(string,substring,start,length)

Parameters:

##ParametersDescription string Required. Specifies the string to be checked. substring Required. Specifies the string to search for. start Optional. Specifies where in the string to begin the search. length Optional. Specifies the length of the search.

Description: Calculate the number of times a substring appears in a string. Substrings are case-sensitive. This function does not count overlapping substrings. This function generates a warning if the start parameter plus the length parameter is greater than the string length.

php substr_count() functionexample

<?php
echo substr_count("I love php.I'm study in php.cn","php");
?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

2
<?php
 $str = "This is php.cn test";
echo substr_count($str,"is",3,9);
?>

Run Instance»

Click the "Run Instance" button to view the online instance

Output:

1

Home

Videos

Q&A