I want to extract the digits from a string that contains numbers and letters like:
"In My Cart : 11 items"
I want to extract the nu
preg_match_all('!\d+!', $some_string, $matches);
$string_of_numbers = implode(' ', $matches[0]);
The first argument in implode in this specific case says "separate each element in matches[0] with a single space." Implode will not put a space (or whatever your first argument is) before the first number or after the last number.
Something else to note is $matches[0] is where the array of matches (that match this regular expression) found are stored.
For further clarification on what the other indexes in the array are for see: http://php.net/manual/en/function.preg-match-all.php