Link to home
Start Free TrialLog in
Avatar of seopti
seopti

asked on

Function eregi() is deprecated

I believe preg_match should be used. What will be the code? Thank you.


1) if(ereg("^[A-Za-z0-9_]{1,255}$",$this->username))

2) if(eregi("^[https?://.+\..+]{1,255}",$this->url))

3) if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",$this->email))

4) if(ereg("^[0-9]{1,6}$",$this->hits))

5)   if(eregi("^[https?://.+\..+]{1,255}",$this->url)
&& eregi("[.+\@.+\..+]{1,255}",$this->email)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here's another example.  Original ereg() expression:
"^[A-Za-z0-9_]{1,255}$"

Open in new window

Updated for preg-type expressions:
$rgx
= '#'       // REGEX DELIMITER
. '^'       // AT START OF STRING
. '['       // START CHARACTER CLSS
. 'A-Z'     // UPPER CASE ALPHA
. 'a-z'     // LOWER CASE ALPHA
. '0-9'     // NUMERIC DIGITS
. '_'       // THE UNDERSCORE
. ']'       // END OF CHARACTER CLASS
. '{1,255}' // LENGTH FROM 1 TO 255
. '$'       // AT END OF STRING
. '#'       // REGEX DELIMITER
;

Open in new window