substr_count
php
number substr_count(string $lancuch, string $igla , [number $start , [number $length]])Returns the number of occurrences of $igla in $lancuch. The optional third argument $start specifies the character at which searching begins.
The search is case-sensitive.
Example:
php
$zdanie = "A cat has a hat";
$ileA = substr_count($zdanie, <code>"A"</code>);
print("Number of A characters in the sentence: ".$ileA);
$ilea = substr_count($zdanie, <code>"a"</code>);
print("Number of a characters in the sentence: ".$ilea);Result:
Number of A characters in the sentence: 1 Number of a characters in the sentence: 4