Bir dize PHP nasıl tekrarlandığını sayısını almak için

1 Cevap php

Gibi bir dize "abc fox fox fox ghi xyz" nasıl ben günlerin tilki 'sayısını alabilirsiniz dize tekrarlanır?

1 Cevap

substr_count() method is indeed very nice, but if you have more needs (for example to match only whole words) here is a regex version using preg_match_all() ve kelime sınırları:

$nb_of_matches = preg_match_all('/\bfox\b/', $subject);

Oldukça basit çok :-)