What are the differences between preg_match() and ereg in PHP when it comes to regular expression matching?
The main difference between preg_match() and ereg in PHP is that preg_match() uses Perl-compatible regular expressions (PCRE) while ereg uses POSIX-compatible regular expressions. PCRE offers more features and flexibility compared to POSIX regex. Therefore, it is recommended to use preg_match() for regular expression matching in PHP.
// Using preg_match() for regular expression matching
$string = "Hello, World!";
if (preg_match("/Hello/", $string)) {
echo "Match found!";
} else {
echo "No match found.";
}