Hi guys,

I'm starting to learn PHP. I tried to use a little email-script on my WAMP 5.3.0 server on localhost, but i'm receiving the same error everythime:

Deprecated: Function ereg() is deprecated in C:\wamp\www\is_email.inc.php on line 14

    if (ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$", $emailadres)) {
        return TRUE;
    } else {
        return FALSE;
    }
}

How can I solve this problem? Thank you!

    preg_match() is the closest function to use
    http://www.php.net/manual/en/function.preg-match.php

    You need to add 2 delimiter chars for example '/'
    at the beginning and end of the regex
    that was used with the old depreciated function (ereg)

    Like this will probably work well:

    if (preg_match("/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$/", $emailadres)) {
        return TRUE;
    } else {
        return FALSE;
    }
    }

      Note that the error message is only a notice: the ereg function will still work, but it is not guaranteed to be supported in future versions of PHP. While I would recommend that the best solution is to replace it with preg_match(), you could simply ensure that notification-level error messages are turned off if you don't want to change it for some reason. Just don't complain to us in a year or two (or 3 or 4?) when your host is upgraded to PHP6 and it no longer works. 😉

        Awesome!

        It works perfect, I just replaced the function to preg_match() and it works as I want it to.

        Thank you

          Write a Reply...