Bizboss Bizboss - 1 year ago 63
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
or any other number.

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