PHP : Find repeated words with and without space in text
问题 I can find repeated words in text with this function: $str = 'bob is a good person. mary is a good person. who is the best? are you a good person? bob is the best?'; function repeated($str) { $str=trim($str); $str=ereg_replace('[[:space:]]+', ' ',$str); $words=explode(' ',$str); foreach($words as $w) { $wordstats[($w)]++; } foreach($wordstats as $k=>$v) { if($v>=2) { print "$k"." , "; } } } thats result me like : bob , good , person , is , a , the , best? Q : how i can get result repeated