php string to int
You can remove the spaces before casting to int
:
(int)str_replace(' ', '', $b);
Also, if you want to strip other commonly used digit delimiters (such as ,
), you can give the function an array (beware though -- in some countries, like mine for example, the comma is used for fraction notation):
(int)str_replace(array(' ', ','), '', $b);
If you want to leave only numbers - use preg_replace like: (int)preg_replace("/[^\d]+/","",$b).