Question

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

Was it helpful?

Solution

Use this:

substr_count($text, ' ');

OTHER TIPS

$arr = count_chars($str,1);
echo $arr[32];

You're looking for preg_match_all.

$numSpaces = preg_match_all('/[ ]/', $testStr, $matches);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top