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