Good question - this is needed when you upgrade to PHP 5.3, where ereg
and eregi
functions are deprecated. To replace
eregi('pattern', $string, $matches)
use
preg_match('/pattern/i', $string, $matches)
(the trailing i
in the first argument means ignorecase and corresponds to the i
in eregi
- just skip in case of replacing ereg
call).
But be aware of differences between the new and old patterns! This page lists the main differences, but for more complicated regular expressions you have to look in more detail at the differences between POSIX regex (supported by the old ereg/eregi/split functions etc.) and the PCRE.
But in your example, you are just safe to replace the eregi call with:
if (preg_match("%{$regex}%i", $url))
return true;
(note: the %
is a delimiter; normally slash /
is used. You have either to ensure that the delimiter is not in the regex or escape it. In your example slashes are part of the $regex so it is more convenient to use different character as delimiter.)