How to get the number of repetitions of a string in PHP
2 answers
The method is substr_count()
really very nice, but if you have more needs (for example, to match only whole words), here is a regex using preg_match_all()
word boundaries as well:
$nb_of_matches = preg_match_all('/\bfox\b/', $subject);
Pretty simple :-)
0
a source to share