What are the advantages of using preg_* functions over ereg in PHP?
The preg_* functions in PHP are more powerful and efficient than the ereg functions. They offer better support for regular expressions and provide more features for pattern matching. Additionally, the preg_* functions are faster and have better error handling capabilities compared to ereg functions.
// Using preg_match to match a pattern in a string
$string = "Hello, World!";
$pattern = '/\bHello\b/';
if (preg_match($pattern, $string)) {
echo "Pattern found in string.";
} else {
echo "Pattern not found in string.";
}