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);
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);
^-- ^ ^^
- change ereg to preg
- add delimeters (
/
) - for case insensitive matches (ereg
i
), add thei
modifier
Deprecated: Function ereg() is deprecated
You must use preg_match
instead of ereg
because the last one is deprecated.
Replacing it is not a big deal:
ereg( "[][{}()*+?.\\^$|]", $_REQUEST['name'] )
will become:
preg_match( "/[][{}()*+?.\\^$|]/", $_REQUEST['name'] )
p.s. I had to modify more than one hundred files while I was porting my old project to PHP 5.3 to avoid manually modifying I've used following script to do it for me:
function replaceEregWithPregMatch($path) {
$content = file_get_contents($path);
$content = preg_replace('/ereg\(("|\')(.+)(\"|\'),/',
"preg_match('/$2/',",
$content);
file_put_contents($path, $content);
}
I hope it helps.
Function ereg_replace() is deprecated - How to clear this bug?
Switch to preg_replace
Docs and update the expression to use preg syntax (PCRE) instead of ereg syntax (POSIX) where there are differencesDocs (just as it says to do in the manual for ereg_replace
Docs).
Alternative to eregi() in php
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';
Good alternative to eregi() in PHP
stristr achieves exactly the same result as eregi (at least when you don't use regular expressions):
if (!stristr($fileName, '.php'))
$filename.='.php';
You could also make a "fake" eregi this way:
if (!function_exists('eregi')) {
function eregi($find, $str) {
return stristr($str, $find);
}
}
Update: Note that stristr
doesn't accept regular expressions as eregi
does, and for this specific case (checking the extension), you'd better go with vartec's solution.
Function eregi_replace() is deprecated
When a function is deprecated, it means it's not supported anymore and the use of it is discouraged. In fact, all eregi
functions are deprecated.
You should try another function, such as preg_replace()
. This could mean you have to edit your regular expression.
This should work
$response = preg_replace ("/\s+/", " ", $response);
$response = preg_replace ("/[\r\n]/", "", $response);
Related Topics
How to Launch a PHP Script at Apache Startup
Connect to Azure Active Directory from PHP Web Application
Html2Pdf in PHP - Convert Utilities & Scripts - Examples & Demos
How to Display Images from a Folder Using PHP - PHP
In Laravel 5, How to Disable Verifycsrftoken Middleware for Specific Route
How to Destroy Session with Browser Closing in Codeigniter
Jquery $.Post Processing JSON Response
Protect the Excel File Using PHPexcel
How to Set Base Url for All Pages of My Website
How to Access the Google Spreadsheets API in PHP
Google Map: Is a Lat/Lng Within a Polygon
Calling a Controller Function in Another Controller in Codeigniter
Getting Elements of a Div from Another Page (Php)
Validate That Input String Does Not Exceed Word Limit