Warning: function eregi() is deprecated [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Function eregi() is deprecated
I have created a contact form with PHP, but am getting a warning:
Deprecated: Function eregi() is deprecated in D:\hosting\9606426\html\Websites\LuxeBeauty\1\contact.php on line 9
This is line 9:
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."#"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-
z]{2,}"."$",$email )){
...
}
What should I do to fix this?

eregi has been depreciated, which means that you'll need to switch to:
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$error.="Invalid email address entered";
$errors=1;
}

Related

PHP 5.1 to PHP 7.1 broke contact form [duplicate]

This question already has answers here:
ereg/eregi replacement for PHP 5.3 [duplicate]
(4 answers)
How to replace eregi()
(2 answers)
How can I convert ereg expressions to preg in PHP?
(4 answers)
Alternative to eregi() in php [duplicate]
(1 answer)
How to change PHP's eregi to preg_match [duplicate]
(2 answers)
Closed 4 years ago.
The web hosting service provider upgraded to PHP 7.1 and it broke the contact form of the page. I've narrowed it down to this piece of code:
function check_email($mail)
{
$email_host = explode("#", $mail);
$email_host = $email_host['1'];
$email_resolved = gethostbyname($email_host);
if ($email_resolved != $email_host && #eregi("^[0-9a-z]([-_.~]?[0-9a-z])*#[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$mail))
$valid = 1; return $valid;
}
I've found that the eregi function is no longer supported in PHP 7.1 but I dont know how and with what i should replace it.
Have a look at the documentation of eregi function in php.net:
Warning
This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.
Alternatives to this function include:
preg_match() (with the i (PCRE_CASELESS) modifier)
You should always have a look there when it comes do deprecated functions.
For validating email addresses you could also use filter_var now:
if (filter_var('test#example.com', FILTER_VALIDATE_EMAIL)) {
echo "Email valid.";
}

I need assistance with eregi - preg_match [duplicate]

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 7 years ago.
I was getting the following error:
Deprecated: Function eregi() is deprecated in /home/herbalhe/public_html/admin/includes/auth.inc.php
So I searched and found that I should be using preg_match() instead of eregi(). So I made the changes and now I am getting this error:
Warning: preg_match(): Unknown modifier 'p' in /home/herbalhe/public_html/admin/includes/auth.inc.php
The code on that line is:
if (preg_match(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) ||
preg_match(".inc.php",$_SERVER['PHP_SELF']))
Any idea what I should now?
It should be:
preg_match("/\.inc\.php$/i", $HTTP_SERVER_VARS['PHP_SELF'])

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

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 9 years ago.
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
{
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
{
}
}
}
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.
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

Alternative to eregi() in php [duplicate]

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 10 years ago.
So, i was using eregi in my mail script, but as of lately, i get the error that the function is deprecated.
So, what is the easiest way to replace the following bit of code:
if (!eregi("^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email'])))?
Any help is appreciated :)
if (!preg_match("/^[A-Z0-9.%-]+#[A-Z0-9.%-]+.[A-Z]{2,4}$/", trim($_POST['email'])))
Using preg_match.
Because ereg_* functions is deprecated in PHP >= 5.3
Also for email validation better used filter_var
if (!filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL))
echo 'Email is incorrect';

Deprecated: Function eregi() [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Function eregi() is deprecated
Hello I am getting this error
Deprecated: Function eregi() is deprecated in /home/u578804202/public_html/includes/functions.php on line 4
Here is my code:
if(eregi($file,$_SERVER['REQUEST_URI'])) {
die("Sorry but you cannot access this file directly for security reasons.");
}
As you should, it's an old function that is deprecated, user stristr() instead
if(stristr($_SERVER['REQUEST_URI'],$file)) {
die("Sorry but you cannot access this file directly for security reasons.");
}
You should use preg_match instead:
if (!preg_match("~{$file}~i,", $_SERVER['REQUEST_URI'])) {
die("Sorry but you cannot access this file directly for security reasons.");
}

Categories