Deprecated: Function eregi() is deprecated in [duplicate]

走远了吗. 提交于 2019-12-10 12:34:20

问题


I'm trying to submit values to the database but i get an error message

Deprecated: Function eregi() is deprecated in C:\wamp\www\OB\admin_add_acc.php on line 20 and 27

Here is the code:

<?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
{                       

回答1:


eregi() is deprecated as of PHP 5.3, use preg_match() instead.

Note that preg_match() is only case insensitive when you pass the i modifier in your regular expression.

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
        {
        }
    }
} 



回答2:


From Wikipedia:

Deprecation is a status applied to a computer software feature, characteristic, or practice indicating it should be avoided, typically because of it being superseded.

Take a look at the PHP manual for eregi. As you can see, it has the following warning:

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

Further down the page there is some advice on what to use instead:

eregi() is deprecated as of PHP 5.3.0. preg_match() with the i (PCRE_CASELESS) modifier is the suggested alternative.

So you can use the preg_match function instead.




回答3:


You can find the answer here in the manual.Since its a Deprecated function in the php version you are using you will get that warning.Instead of ergi you can use preg_match.See the manual for preg match



来源:https://stackoverflow.com/questions/18509858/deprecated-function-eregi-is-deprecated-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!