2011-02-27 143 views
-1

我正在使用此php代码。但它给错误弃用:函数eregi()已弃用,如何解决此错误?

推荐使用:功能eregi()是 弃用 C:\ XAMPP \ htdocs中\上 线7

<? 
include_once("mastersecure.php"); 
$emailcheck=$_POST["member_name"]; 
function isValidEmail($email){ 
     $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; 

     if (eregi($pattern, $email)){ 
     return true; 
     } 
     else { 
     return false; 
     } 
    } 
    if (!isValidEmail($_POST['member_name'])){ 
       echo "The email is invalid!"; 
      } 
    else 
    { 
     $query="select email from fuel where email='$_POST[member_name]'"; 
     $res=mysql_query($query); 
     $rowcount=mysql_num_rows($res); 
     if($rowcount!=0) 
     { echo "This mail is already exits"; } 
    }  
?> 

此Any溶液燃料\ emailcheck.php ?

+0

可能重复的[如何解决EREG函数弃用错误](http://stackoverflow.com/questions/4825205/how-to -solve-the-ereg-function-deprecated-error) – Gordon 2011-02-27 10:31:35

+0

[PHP-Email Validation](http://stackoverflow.com/questions/4906608/php-email-validation) – Gordon 2011-02-27 10:33:54

+0

*(相关)* [Does FILTER_VALIDATE_EMAIL制作一个字符串安全插入数据库?](http://stackoverflow.com/questions/4154685/does-filter-validate-email-make-a-string-safe-for-insertion-in-database) – Gordon 2011-02-27 10:35:00

回答

0

使用

<? 
include_once("mastersecure.php"); 
$emailcheck=$_POST["member_name"]; 
function isValidEmail($email){ 
     $pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i"; 

     if (preg_match($pattern, $email)){ 
     return true; 
     } 
     else { 
     return false; 
     } 
    } 
    if (!isValidEmail($_POST['member_name'])){ 
       echo "The email is invalid!"; 
      } 
    else 
    { 
     $query="select email from fuel where email='$_POST[member_name]'"; 
     $res=mysql_query($query); 
     $rowcount=mysql_num_rows($res); 
     if($rowcount!=0) 
     { echo "This mail is already exits"; } 
    }  
?> 

http://php.net/manual/en/function.preg-match.php

http://php.net/manual/en/function.eregi.php

+0

您能否修改我的代码与修复? – 2011-02-27 07:20:17

+0

我是否需要用'preg_match($ pattern,$ email)'''替换'eregi($ pattern,$ email))''? – 2011-02-27 07:21:26

+0

不是很有帮助的答案,因为模式也应该改变。但是,它似乎不是程序员,而是用户问题。 – 2011-02-27 07:21:55

相关问题