Bizboss Bizboss - 4 months ago 11
PHP Question

Extract numbers from a string

I want to extract the numbers from a string that contains numbers and letters like:

"In My Cart : 11 items"


I want here to get the number
11
or any other number.

Answer
$str = 'In My Cart : 11 12 items';
preg_match_all('!\d+!', $str, $matches);
print_r($matches);