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
Related
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.";
}
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
I know there are a lot of questions related to this subject, but after some days of research I didn't find something that could help this particular case, so here it is:
I have replaced the deprecated eregi with preg_match in 2 files of my website, and now the capcha code gives an error on the registration page, even if the code is absolutely correct
On the registration page I have replaced this
function is_valid_username($username) {
if(!eregi("^[a-z0-9]*$", trim(str_replace(" ","",$username)))) {
return 0;
}
with this
if(!preg_match("^[a-z0-9]*$^", trim(str_replace(" ","",$username)))) {
return 0;
}
And in my second file I have replaced this:
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
$result = 0;
}
with this
if(!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$^", $email)) {
$result = 0;
}
How can I resolve this issue?
eregi is case-insensitive, so you would need to add the i modifier to the end of your preg_match expression.
Also, ^ denotes the start of the input and you have used it as the delimiter.
So this should be more like the original:
#^[a-z0-9]*$#i
and
#^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$#i
By the way, I don't know what your captcha code requires exactly, but there are easier ways to verify an email address using filter_var().
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.");
}
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
i am using php 5.3.0 and i am use wamp server
function is like that
eregi("^[ \f\r\t\n]{0,}(SELECT){1}(.+)$",$this->ss_last_query)
eregi("^[ \f\r\t\n]{0,}(UPDATE|INSERT|DELETE){1}(.+)$",$this->ss_last_query)
Two options
Don't use the ereg* functions (use the PCRE suite instead)
Disable E_DEPRECATED error reporting. See error_reporting()
The best option is #1 as the entire POSIX Extended suite will be removed in a future version.
I can't comprehend how people are still using this. It's been marked for removal for years. Not to mention the pre-deprecated "These functions are inferior!" warning that was up for even longer.
Use the preg_match with the i modifier, which specifies that you want a case insensitive match with your regex.
So you want:
preg_match("/regexhere/i", $str);
error_reporting(E_ALL ^ E_DEPRECATED);
If you must use eregi, but...
preg_match("/^[ \f\r\t\n]{0,}(UPDATE|INSERT|DELETE){1}(.+)$/is", $this->ss_last_query)
should also work.
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
I am working with SEO PHP scripts and I am just following Google SEO scripts. When I used the search terms I got an error like the following:
Deprecated: Function eregi() is deprecated in E:\wamp\www\subgoogle\nusoap.php on line 3876
Deprecated: Function ereg() is deprecated in E:\wamp\www\subgoogle\nusoap.php on line 3896
Deprecated: Function ereg() is deprecated in E:\wamp\www\subgoogle\nusoap.php on line 1451
How should I remove that error function? Is there any need to use a library?
eregi() function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
you can use preg_match().
http://php.net/manual/en/function.eregi.php
Note:
As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED notice. See the list of differences for help on converting to PCRE.
You need to convert every use of ereg* to an equivalent function of the preg_* family. Or, as #Srisa rightly points out, look for an updated version of the library/script in question.
error_reporting( 0 ) ;
That's how you can eliminate the symptoms, but to cure the disease you just shouldn't use POSIX regular expressions, change them to PCRE
you may want to check this brunch http://sourceforge.net/projects/nusoapforphp53/
it works for me
Change ereg() to mb_ereg.hope which fixes your error. Good luck!