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.";
}
Related
This question already has answers here:
Alternative for deprecated PHP function: eregi_replace [duplicate]
(2 answers)
Closed last year.
can someone show me how to convert this please
eregi_replace(":rolleyes:", "<img src='./images/smilies/icon_rolleyes.gif' border='0'> ", $
i have tried lookin gonline but carnt get my head around it keep getting this error
keep getting
PHP Deprecated: Function eregi_replace() is deprecated in
The eregi_replace function is deprecated as of PHP 5.3. You should use preg_replace with the i modifier instead:
preg_replace('/:rolleyes:/i', '<img src="./images/smilies/icon_rolleyes.gif" border="0">', $var);
This question already has answers here:
PHP 7.2 Function create_function() is deprecated
(6 answers)
Closed 1 year ago.
I have a function which im not entirely sure how to convert it to get working in newest php
$eventSponsor = array_map(create_function('$o', 'return $o["id"];'), $event->sponsors);
which method should i use in newest php version ?
yeah i was searching and i found this method called anonymous function so the code be like
$awe function ($o) {
return $o["id"];
};
$eventSponsor = array_map($awe,$event->sponsors); ```
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
below code is giving me the fatal error in php 7
$jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));
is there any way to make it compatible with php 7?
Switch to preg_replaceDocs 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_replaceDocs).
Your above code should be this way:
$jquery_click_hook = preg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));
ereg_replace function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0. So you must have to use preg_replace() function instead of ereg_replace()
This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
How to validate an Email in PHP?
(7 answers)
How to validate an email address in PHP
(15 answers)
Closed 9 years ago.
Deprecated code:
function validate_email($email)
{
return eregi("^[_\.0-9a-zA-Z-]+#([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $email);
}
I am a JavaScript beginner. The above code gives an error. I am not too sure how to rewrite using preg_match.
Try this instead
function validate_email($email)
{
return (1 === preg_match("/^[_\.0-9a-zA-Z-]+#([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email));
}
preg_match() should be used rather than eregi. You must include the slashes at the begining and end of the pattern. And finally, the "/i" at the end of the pattern makes it case-insensitive.
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';