Koşulu kapatana kadar olan kısmı paylaşır mısınız? Bir de substr_count yerine preg_match deneyin.