php leave only number in string code example Example: php keep only numbers in string $str = preg_replace('/[^0-9.]+/', '', $str);