I have tried to use preg_match to match the spaces but it returns one always. How can I get the number of spaces in this string? In this case it should return 8
. Any use PHP function is ok.
$string = "The quick brown fox jumps over the lazy dog";
I have tried to use preg_match to match the spaces but it returns one always. How can I get the number of spaces in this string? In this case it should return 8
. Any use PHP function is ok.
$string = "The quick brown fox jumps over the lazy dog";
Actually you could also use substr_count
for this:
$string = "The quick brown fox jumps over the lazy dog";
echo substr_count($string, ' '); // 8
use this:
substr_count($text, ' ');
substr_count — Count the number of substring occurrences