I want to check how many instances of the letter a
appears in a certain string.
What is the function for this? I need it to return an integer value.
I suppose substr_count could do the trick ;-)
For example, this portion of code :
$str = 'abcdazerty';
echo substr_count($str, 'a');
would get you the following output :
2
And, quoting :
int substr_count ( string $haystack ,
string $needle [, int $offset = 0
[, int $length ]] )
substr_count()
returns the number of times theneedle
substring occurs in thehaystack
string. Please note that needle is case sensitive.