PHP – Extract Numbers from a String

This following PHP example helps you to extract the numbers from a string that contains numbers 
and letters.

Code Example:

<?php
$str = 'In My Cart : 12 14 items';
preg_match_all('!\d+!', $str, $matches);
print_r($matches);
?>

Output:

Array
(
    [0] => Array
        (
            [0] => 12
            [1] => 14
        )

)

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail