Deprecated: eregi () function deprecated in

I am trying to pass values ​​to a database, but I am getting an error

Deprecated: the eregi () function has deprecated in C: \ wamp \ www \ OB \ admin_add_acc.php on lines 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 { 
+12
source share
3 answers

eregi() deprecated since PHP 5.3, use preg_match() .

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

 include 'db_connect.php'; if(isset($_POST['Submit'])) { $acc_type=ucwords($_POST['acc_type']); $minbalance=ucwords($_POST['minbalance']); // Removed AZ here, since the regular expression is case-insensitive if (!preg_match("/^[az ]+$/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 { } } } 
+18
source

From Wikipedia :

Obsolescence is a status that is applied to a software function, feature, or practice, indicating that this should be avoided, usually because it is being replaced.

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

This function has been DEPRECATED since PHP 5.3.0. Based on this feature, it is highly discouraged.

Further on the page there are some tips on what to use instead:

eregi () has been deprecated since PHP 5.3.0. preg_match () with modifier i (PCRE_CASELESS) is the recommended alternative.

That way you can use preg_match .

+2
source

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

0
source

Source: https://habr.com/ru/post/952733/


All Articles