$str = 'now a man ,then comes so many men here.'; $res = array_count_values(str_word_count($str, 1)); echo $res['men'] + $res['man'];
function countWords($str) { preg_match_all("/m[ae]n/",$str,$matches); return count($matches); } $string = "now a man ,then comes so many men here."; echo countWords($string);
这样human,menu什么的也都会算进去的,在两边定下界才行 function countWords($str) { preg_match_all("/[^a-zA-Z]m[ae]n[^a-zA-Z]/",$str,$matches); return count($matches); } $string = "now a man ,then comes so many men here."; echo countWords($string);
那就没有办法了,除非你做一个字典,这个字有哪些也需要算进去的。
$str = 'now a man ,then comes so many men here.';
$res = array_count_values(str_word_count($str, 1));
echo $res['men'] + $res['man'];
function countWords($str)
{
preg_match_all("/m[ae]n/",$str,$matches);
return count($matches);
}
$string = "now a man ,then comes so many men here.";
echo countWords($string);
function countWords($str)
{
preg_match_all("/[^a-zA-Z]m[ae]n[^a-zA-Z]/",$str,$matches);
return count($matches);
}
$string = "now a man ,then comes so many men here.";
echo countWords($string);