Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们如何计算 PHP 中文本之间的空格?
example: hi how are you? spaces: 3
有没有办法计算空间?
语言:只有 PHP
用这个:
substr_count($text, ' ');
你正在寻找preg_match_all.
preg_match_all
$numSpaces = preg_match_all('/[ ]/', $testStr, $matches);
$arr = count_chars($str,1); echo $arr[32];