不推荐使用:函数eregi()在中不推荐使用


Deprecated: Function eregi() is deprecated in

我试图向数据库提交值,但收到错误消息

不推荐使用:函数eregi()在中不推荐使用C: 第20和27行的''wamp''www''OB''admin_add_acc.php

这是代码:

<?php       
include 'db_connect.php'; 
if(isset($_POST['Submit']))           
{            
$acc_type=ucwords($_POST['acc_type']);
$minbalance=ucwords($_POST['minbalance']);                       
if (!eregi ("^[a-zA-Z ]+$", stripslashes(trim($acc_type))))//line 20 
{                 
echo "Enter Valid Data for Account Type!";                
exit(0);                 
}           
else 
{                  
if (!eregi ("^[0-9 ]+$", stripslashes(trim($minbalance))))//line 27
{                       

eregi()从PHP 5.3起已弃用,请改用preg_match()

请注意,当在正则表达式中传递i修饰符时,preg_match()仅不区分大小写。

include 'db_connect.php'; 
if(isset($_POST['Submit']))           
{            
    $acc_type=ucwords($_POST['acc_type']);
    $minbalance=ucwords($_POST['minbalance']);
    
    // Removed A-Z here, since the regular expression is case-insensitive                
    if (!preg_match("/^[a-z ]+$/i", stripslashes(trim($acc_type))))//line 20 
    {                 
        echo "Enter Valid Data for Account Type!";                
        exit(0);                 
    }           
    else 
    {                  
        // 'd and 0-9 do the same thing
        if (!preg_match("/^['d ]+$/", stripslashes(trim($minbalance))))//line 27
        {
        }
    }
} 

来自维基百科:

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

看看eregi的PHP手册。正如你所看到的,它有以下警告:

自PHP 5.3.0起,此函数已弃用。强烈反对依赖此功能。

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

自PHP 5.3.0起,eregi()已被弃用。带有i(PCRE_CASELESS)修饰符的preg_match()是建议的替代方法。

因此,您可以使用preg_match函数。

您可以在手册中找到答案。由于在您使用的php版本中它是一个不推荐的函数,您将收到该警告。您可以使用preg_match而不是ergi。有关预匹配的信息,请参阅手册