tjyoung
asked on
How to rewrite ereg to preg_match
Hi,
I'm trying to figure out how to change the below code so it doesn't use ereg as I'm getting a deprecated error and I believe I should be using preg_match. I simply dropped in preg_match and not surprisingly, it failed with this error:
Warning: preg_match(): No ending delimiter '^'
What I'm trying to accomplish it to tell if the '$fromcaller' variable is an ip number or not and if so, 'do this' or else 'do that'. If there is a better/cleaner way of doing it, I'm all ears.
This is the snippet I'm using:
I'm trying to figure out how to change the below code so it doesn't use ereg as I'm getting a deprecated error and I believe I should be using preg_match. I simply dropped in preg_match and not surprisingly, it failed with this error:
Warning: preg_match(): No ending delimiter '^'
What I'm trying to accomplish it to tell if the '$fromcaller' variable is an ip number or not and if so, 'do this' or else 'do that'. If there is a better/cleaner way of doing it, I'm all ears.
This is the snippet I'm using:
if (ereg("^([0-9]{1,3})x2E([0-9]{1,3})x2E([0-9]{1,3})x2E([0-9]{1,3})$", $fromcaller, $digit)) {
if (($digit[1] <= 255) && ($digit[2] <= 255) && ($digit[3] <= 255) && ($digit[4] <= 255)) {
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the points, and a great New Year to you, too!
If you find that you have eregi() in your code, that is the case-insensitive version of the regular expression. In that case, you can add the letter i after the last regex delimiter and the preg engine will become case-insensitive.
If you find that you have eregi() in your code, that is the case-insensitive version of the regular expression. In that case, you can add the letter i after the last regex delimiter and the preg engine will become case-insensitive.
ASKER
Have a great 2013 Ray.