Function Eregi() Is Deprecated

Deprecated: Function eregi() is deprecated in

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

Deprecated: Function eregi_replace()

the entire ereg family of functions are deprecated in PHP and will at some point be removed from the language. The replacement is the preg family. For the most part, the change is simple:

preg_replace('/[^<>]>/i', '', $question);
^-- ^ ^^
  1. change ereg to preg
  2. add delimeters (/)
  3. for case insensitive matches (eregi), add the i modifier

Deprecated: Function eregi() is deprecated

Normally, you should use the preg_* family of regular expression matching. However, most of your ereg calls actually just search case insensitive. Instead of

!eregi("install", $_SERVER['PHP_SELF'])

use

stripos($_SERVER['PHP_SELF'], 'install') === false

. With preg_match, this would look like this:

!preg_match('/install/i', $_SERVER['PHP_SELF'])

Alternative for deprecated PHP function: eregi_replace

preg_replace

https://php.net/preg-replace

$pattern = "/([a-z0-9][_a-z0-9.-]+@([0-9a-z][_0-9a-z-]+\.)+[a-z]{2,6})/i";
$replace = "<a href=\"mailto:\\1\">\\1</a>";
$text = preg_replace($pattern, $replace, $text);

PHP Form Validation - Deprecated Function eregi()

Regex has the "case-insensitive" way to match a string. If you put the letter "i" at the end of the regular expression, the function preg_match() will match the string even if you are searching a lowercase sentence in an uppercase string.

In the case ALPHA, you can use this regular expression:

$exp = "/^[a-z]+$/i";

instead of

$exp = "^[a-z]+$";

Using this, you can change the PHP functions from eregi($exp, $value) to preg_match($exp, $value), which will return TRUE if there are matches.

You can read the related documentation of preg_match() function here: https://www.php.net/manual/en/function.preg-match.php

Andrea



Related Topics



Leave a reply



Submit