将eregi更改为preg_match后系统停止工作

时间:2019-06-01 08:15:57

标签: php preg-match eregi

在我的网站上,我有一个与我们联系的表格,该表格在我升级到php 7之前一直可以正常工作。现在,当我填写表格时,它以无效电子邮件的形式返回,并且日志没有显示任何错误。

之前显示为错误

PHP Fatal error:  Uncaught Error: Call to undefined function eregi() in /app/index.php:27

这是第27行:

 if (!empty($email) && !preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
        $err[] = "Invalid email<br>";
    }

所以我将eregi更改为preg_match,但现在它不起作用了。

<?php
$err=array();

if(count($_POST) > 0)
{

    $name = isset($_REQUEST["name"]) ? trim($_REQUEST["name"]) : "";
    $address = isset($_REQUEST["subject"]) ? trim($_REQUEST["subject"]) : "";
    $country = isset($_REQUEST["country"]) ? trim($_REQUEST["country"]) : "";
    $email = isset($_REQUEST["email"]) ? trim($_REQUEST["email"]) : "";
    $contact_no = isset($_REQUEST["contact_no"]) ? trim($_REQUEST["contact_no"]) : "";
    $budget = isset($_REQUEST["budget"]) ? trim($_REQUEST["budget"]) : "";
    $com_name = isset($_REQUEST["com_name"]) ? trim($_REQUEST["com_name"]) : "";
    $message_text = isset($_REQUEST["message_text"]) ? trim(addslashes($_REQUEST["message_text"])) : "";
    $message_text=htmlentities($message_text,ENT_QUOTES);


    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date = date("F j, Y, g:i a"); 


    if(empty($name)) $err[]="You must enter your name,";
    if(empty($email)) $err[]="proper email address,";

    if (!empty($email) && !preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
        $err[] = "Invalid email<br>";
    }
    if(empty($contact_no)) $err[]="proper contact no";

    if(!empty($contact_no) && !(is_numeric($contact_no)) )
    $err[]="Contact No must be in Number<br>";

0 个答案:

没有答案