函数eregi()已弃用(对我而言)

时间:2014-08-06 10:47:38

标签: php

我的网站上有一个联系表格:

  

不推荐使用:函数eregi()已弃用   /home/sessionj/domains/XXX.com/public_html/test/contactform.php on   第12行

但电子邮件是发给我的,“小心”很烦人。

任何不好的代码?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="css/style.css" />
<title> Contact Form</title>
</head>
<body>
<?php
function is_valid_email($vemail) {
$result = TRUE;
     if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",    $vemail)) {
$result = FALSE;
}
   return $result;
  }
//if "email" is filled out, send email
if (isset($_REQUEST['email']) && $_REQUEST['email'] != '' && $_REQUEST['name'] != '' && $_REQUEST['message'] != ''
&& is_valid_email($_REQUEST['email']))
{
//send email
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$recievers_email = "info@xxx.com";

mail($recievers_email, "$subject",
$message, "From:" . $email);
echo "<p class='form_success'>Message sent! Thank you!</p><p class='form_success_sub'>We'll reply as soon as possible, SJ.</p>";
}
else
{
 //if "email" is not filled out, display the form
if(!is_valid_email($_REQUEST['email']))
{
    echo "<p class='form_error'>Please, insert an email address.</p>";                         
 }
else if($_REQUEST['name'] == '')
{
    echo "<p class='form_error'>Please, write your name.</p>";
}
else if($_REQUEST['message'] == '')
{
    echo "<p class='form_error'>Please, leave your message.</p>";
}
}
?>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

弃用是指应用于计算机软件功能,特征或实践的状态,表明应该避免,通常是因为它被取代。

查看eregi的PHP手册。如您所见,它有以下警告:

自PHP 5.3.0起,此功能已被弃用。非常不鼓励依赖此功能。

在页面下方有一些关于使用什么的建议:

自PHP 5.3.0起,不推荐使用eregi()。带有i(PCRE_CASELESS)修饰符的preg_match()是建议的替代方法。

所以你可以使用preg_match函数。