PHP,我想计算一个字符串中包含六个以上字母的单词数

I want to count the number of words in a string with more than six letters.

For example:

$x = number of words with more than 6 letters("Elephant shoe penguin food telephone"); $x=3;

Do you know how?

Use regexp:

$x = preg_match_all("/\\w{6,}/", "Elephant shoe penguin food telephone", $matches);

You can explode the string and check with strlen for more then 6 chars.

$x = 0;
$string = "Elephant shoe penguin food telephone";
$explString = explode(" ", $string);
foreach($explString as $word){
   if(strlen($word > 6)){
       $x++;
   }
}

echo $x; //Returns 3;