»Forumlar »D?k?manlar »How to fix ‘Function eregi() is deprecated’ in PHP 5.3.0?
  https://seditio.com.tr/eski1/forums.php?m=posts&q=1742
          Geri Dön      -      Sayfayı Yazdırmak için tıklayın
Author: Kaan, Posted: 2012-01-04 00:10 GMT.
used to use eregi for validating email address input that matches to the regular expression.

?rnek:
Kod:
if(!eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $str)) {
    $msg = 'email is not valid';
}
else {
$valid = true;
}

That would return true if given email address is matches to username@domain.ext pattern. Unfortunately, after upgrading PHP to the earlier version (5.3.0), it wont work properly. This is because eregi is one of several functions that are deprecated in the new version of PHP.


Solution how to fix Function Deprecated:

Use preg_match with the 'i' modifier instead. i means that regular expression is case insensitive. So the code become like this:

Yerine alttaki gibi olmal?
Kod:
if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $str)) {
    $msg = 'email is not valid';
}
else {
$valid = true;
}

The list of functions that are deprecated in PHP 5.3.0:

call_user_method() (use call_user_func() instead)
call_user_method_array() (use call_user_func_array() instead)
define_syslog_variables()
dl()
ereg() (use preg_match() instead)
ereg_replace() (use preg_replace() instead)
eregi() (use preg_match() with the 'i' modifier instead)
eregi_replace() (use preg_replace() with the 'i' modifier instead)
set_magic_quotes_runtime() and its alias, magic_quotes_runtime()
session_register() (use the $_SESSION superglobal instead)
session_unregister() (use the $_SESSION superglobal instead)
session_is_registered() (use the $_SESSION superglobal instead)
set_socket_blocking() (use stream_set_blocking() instead)
split() (use preg_split() instead)
spliti() (use preg_split() with the 'i' modifier instead)
sql_regcase()
mysql_db_query() (use mysql_select_db() and mysql_query() instead)
mysql_escape_string() (use mysql_real_escape_string() instead)
Passing locale category names as strings is now deprecated. Use the LC_* family of constants instead.
The is_dst parameter to mktime(). Use the new timezone handling functions instead.

Ref: http://php.net/manual/en/migrati.....cated.php


Incoming search terms:

Function eregi() is deprecated
Function ereg() is deprecated
Deprecated: Function eregi() is deprecated in
Deprecated: Function eregi() is deprecated
eregi
eregi deprecated
Function eregi() is deprecated in
Deprecated: Function ereg() is deprecated
Deprecated: Function ereg() is deprecated in
eregi is deprecated

Powered by SeditioPrint version