Are there alternative methods or functions in PHP that can achieve the same result as the ereg function in this context?

The ereg function is deprecated in PHP 5.3.0 and removed in PHP 7.0.0. To achieve the same result as the ereg function, you can use the preg_match function in PHP, which uses Perl-compatible regular expressions. Simply replace the ereg function with preg_match and update the regular expression pattern accordingly.

// Original code using ereg
if (ereg('^[0-9]+$', $input)) {
    echo 'Input is a number';
} else {
    echo 'Input is not a number';
}

// Updated code using preg_match
if (preg_match('/^[0-9]+$/', $input)) {
    echo 'Input is a number';
} else {
    echo 'Input is not a number';
}