If you just want to filter everything other than the numbers out, the easiest is to use filter_var
:
$str = 'In My Cart : 67 items'; $int = (int) filter_var($str, FILTER_SANITIZE_NUMBER_INT);
If you just want to filter everything other than the numbers out, the easiest is to use filter_var
:
$str = 'In My Cart : 67 items'; $int = (int) filter_var($str, FILTER_SANITIZE_NUMBER_INT);