2011-02-27 169 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

相關問題