Php5.3x no longer supports Ereg and eregi, workaround

Source: Internet
Author: User
Tags deprecated ereg
Php5.3x no longer supports Ereg and Eregi, solutions
I am currently engaged in PHP programmers, Web site direction. The functions that have encountered PHP before have been deprecated, mainly the PHP version problem (php5.3.x), in order to better transition to a future version of PHP (PHP6), the future no longer support functions marked as DEPRECATED. Using these functions in your code will not hesitate to display a warning message in the page: "Using obsolete functions ...", these configurations will no longer exist in the PHP6, and related functions will also be turned off
Some of the deprecated functions are listed below:
Call_user_method ()(using Call_user_func ()Alternative
Call_user_method_array ()(using Call_user_func_array ()Alternative
define_syslog_variables ()
DL ()
Ereg ()(using Preg_match ()Alternative
ereg_replace ()(using preg_replace ()Alternative
eregi ()(using Preg_match ()Replace with ' i ' modifier)
eregi_replace ()(using preg_replace ()Replace with ' i ' modifier)
set_magic_quotes_runtime ()and its alias function. magic_quotes_runtime ()
[Color=olive]session_register ()(using $_sessionSuper all variable substitution)
Session_unregister ()(using $_session Super All variablesAlternative
session_is_registered ()(using $_session Super All variablesAlternative
set_socket_blocking ()(using stream_set_blocking ()Alternative
Split ()(using Preg_split ()Alternative
Spliti ()(using Preg_split ()Replace with ' i ' modifier)
sql_regcase ()
mysql_db_query ()(using mysql_select_db ()And mysql_query ()Alternative
mysql_escape_string ()(using mysql_real_escape_string ()Alternative
Obsolete to pass the locale name as a string. Use lc_*Series constant substitution.
mktime ()Of IS_DSTParameters. Use the new time zone handler function override.

The main function migration involved is as follows:
Delete function Define_syslog_variables Reference Delete reference to function Define_syslog_variables $LOG _err, $LOG _user, etc. with constant log_user, Log_user, ... Alternative
Ereg, Eregifunction with Preg_matchFunctions that override these functions declare int ereg (String$pattern, String $string [, Array & $regs]) int eregi (string $pattern, String $str ing [, array & $regs]) Intpreg_match (string $pattern, String $subject [, Array & $matches [, int $flags [, int $offset]]) Although the first parameter of the three is a string representing a regular expression, Preg_match uses the PCRE (Perl-compatible regular expression syntax): the ends of a regular expression are bounded by a symbol, such as "/pattern/" or "#pattern #", the eregi is a slightly case-sensitive match, converted to Preg_match, the first argument, Use the parameters of the pcre to slightly case, such as: "/pattern/i" or "#pattern #i", the third parameter of the two returns a different structure of the matching data. The third parameter of Ereg, after the call is finished, returns an array of strings, each of which is the complete matching string and each sub-matching string. Preg_match returns a two-dimensional array, which is equivalent to a string in an array of ereg strings, where Preg_match is an array, preserving the matching values and matching positions, respectively. If multiple matches are to be made, PHP provides the Preg_match_all function, and the return value of its third parameter is a three-dimensional array.
ereg_replace, Eregi_replacefunction with Preg_replacefunction or Str_replace function to replace the previous ereg with Preg_match similar, the first parameter to be converted, the head and tail to add a symbol, such as: "/pattern/" or "#pattern #", ... eregi_replace to Preg Replace the _replace, adding a regular expression parameter after the first argument. such as: "/pattern/i" or "#pattern #i", ... If the first parameter of Ereg_replace is not a regular expression, you can replace it with str_replace directly.
Splitifunction with ExplodeDolly Mix Preg_splitfunction instead of split splitting string, If you don't need a regular expression, it's best to replace it with explode, which is the fastest.For using a regular expression to slice a string, use the Preg_split function instead. The substitution process is similar to ereg/ereg_replace, just a fuss in the first regular expression argument, with the split regular expression preceded and followed by a PCRE separator symbol.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.