$string = 'Count my chars without spaces, please !';
$count_spaces = substr_count($string, ' ');
$count_chars_altogether = strlen($string);
$count_chars_without_spaces = $count_chars_altogether-$count_spaces;
echo "This string contains <b>".$count_spaces."</b> spaces.<br />";
echo "This string contains <b>".$count_chars_altogether."</b> chars altogether.<br />";
echo "This string contains <b>".$count_chars_without_spaces."</b> chars without spaces !";
output:
This string contains 6 spaces.
This string contains 39 chars altogether.
This string contains 33 chars without spaces !