不推荐使用:函数eregi()已弃用,如何解决此错误?

时间:2011-02-27 07:18:28

标签: php xampp

我正在使用这个PHP代码。但它给出了错误

  

不推荐使用:函数eregi()是   不推荐使用   C:\ xampp \ htdocs \ fuel \ emailcheck.php on   第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"; }
     }      
?>

对此有何解决方案?

1 个答案:

答案 0 :(得分: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