how to count space in a text statement in php

霸气de小男生 提交于 2019-12-18 19:45:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!