Depending on your use case, this might also be an option:
$str = 'In My Cart : 11 items';
$num = '';
for ($i = 0; $i < strlen($str); $i++) {
if (is_numeric($str[$i])) {
$num .= $str[$i];
}
}
echo $num; // 11
Though I'd agree a regex or filter_var()
would be more useful in the stated case.