Why is it recommended to use preg_match() instead of ereg() for regular expression matching in PHP?
Using preg_match() is recommended over ereg() for regular expression matching in PHP because preg_match() is faster and more efficient. ereg() is deprecated as of PHP 5.3.0 and removed in PHP 7. preg_match() provides more features and flexibility in pattern matching compared to ereg().
// Using preg_match() for regular expression matching
$string = "Hello, World!";
$pattern = "/Hello/";
if (preg_match($pattern, $string)) {
echo "Pattern found in the string.";
} else {
echo "Pattern not found in the string.";
}