Well since internally I think a string is just a char array, we can do something like this
<?php
$string = "This(# % 6 string";
$whitespace = 0;
for ($i = 0; $i < strlen($string); $i++) {
if ($string[$i] != " ")
echo $string[$i] . "<br>";
else
$whitespace++;
}// end for
echo "There are $whitespace white spaces";
?>
This might not be the cleanest method but it works.
Hope that helps