Use str_replace
to remove the spaces first ?
You can use the str_replace
when you declare your variable $b like that :
$b = str_replace(" ", "", '88 8888');
echo (int)$b;
Or the most beautiful solution is to use intval :
$b = intval(str_replace(" ", "", '88 8888');
echo $b;
If your value '88 888' is from an other variable, just replace the '88 888' by the variable who contains your String.
Replace the whitespace characters, and then convert it(using the intval function or by regular typecasting)
intval(str_replace(" ", "", $b))
What do you even want the result to be? 888888? If so, just remove the spaces with str_replace
, then convert.
If you want to leave only numbers - use preg_replace like: (int)preg_replace("/[^\d]+/","",$b).
Source: Stackoverflow.com