问题
how can we count space between text in php ?
example: hi how are you?
spaces: 3
is there any way to count spaces ?
Language : Only PHP
回答1:
Use this:
substr_count($text, ' ');
回答2:
$arr = count_chars($str,1);
echo $arr[32];
回答3:
You're looking for preg_match_all.
$numSpaces = preg_match_all('/[ ]/', $testStr, $matches);
来源:https://stackoverflow.com/questions/1034017/how-to-count-space-in-a-text-statement-in-php