Link to home
Create AccountLog in
Avatar of gpinzino
gpinzino

asked on

Converting Regular Expressions from PHP4 to PHP5.3

I have the dubious job of upgrading a very large website (19,000+ items) from PHP4 to PHP5.3. My initial investigation revealed that there are about 1000 statements using “ereg”, “eregi” and “ereg_replace”. A little research tells me that simply replacing ereg with “preg_match" is insufficient. It appears I must also modify the expression to conform to “Perl-compatible regular expression syntax”.

I have very minimal skills with regular expressions. What basic steps do I need to take to make these statements PHP5.3 compliant?

Also, here are a couple of examples of regular expressions from the site. Please modify them as required so that I can see something that illustrates your answer. A short explanation of what the statement is doing would also help greatly. If you wish to provide other examples, all the better.

$session_key = ereg_replace('sess_', '', $file);

Open in new window

and
// check an email address is possibly valid
	  if (ereg('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', $address))
	    return true;
	  else 
	    return false;
	}

Open in new window

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of gpinzino
gpinzino

ASKER

Thanks. I appreciate how prompt and thorough you both are.
Thanks for the points, and thanks for using EE.  I'm sure your question will be helpful to others who face the same issues! Best, ~Ray