I'm sorry to ask a question but I am useless when it comes to understanding regex code.
In a php module that I didn't write is the following function
function isURL($url = NULL) {
if($url==NULL) return false;
$protocol = '(http://|https://)';
$allowed = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)';
$regex = "^". $protocol . // must include the protocol
'(' . $allowed . '{1,63}\.)+'. // 1 or several sub domains with a max of 63 chars
'[a-z]' . '{2,6}'; // followed by a TLD
if(eregi($regex, $url)==true) return true;
else return false;
}
Can some kind soul give me the replacement code for that with whatever is required to replace the eregi
Did you want a complete replacement to preg_match and eregi?
Or for Email:
Good question - this is needed when you upgrade to PHP 5.3, where
ereg
anderegi
functions are deprecated. To replaceuse
(the trailing
i
in the first argument means ignorecase and corresponds to thei
ineregi
- just skip in case of replacingereg
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:
(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.)eregi
is depreciated in PHP you have to usepreg_match
Please see http://php.net/manual/en/function.preg-match.php for more information Thanks
:)
Palliative PHP 5.3 until you replace all deprecated functions