Php5.3x no longer supports ereg and eregi. Solution

Source: Internet
Author: User
Tags ereg
Php5.3x does not support ereg and eregi any more. The solution is for PHP programmers and websites. many PHP functions have been discarded before, mainly due to PHP version issues (PHP5.3.x). in order to better transition to PHP's future version (PHP6, mark the functions that are no longer supported in the future as DEP php5.3x does not support ereg and eregi. Solution
I am currently engaged in PHP programmers and websites. many PHP functions have been discarded before, mainly due to PHP version issues (PHP5.3.x). in order to better transition to PHP's future version (PHP6, mark functions that are no longer supported as DEPRECATED. using these functions in code will show a warning message on the page without mercy: "outdated functions... ", These configurations will no longer exist in PHP6, and related functions will also be disabled
Some discarded functions are listed below:
Call_user_method () (use call_user_func)
Call_user_method_array () (use call_user_func_array)
Define_syslog_variables ()
Dl ()
Ereg () (use preg_match () instead)
Ereg_replace () (use preg_replace)
Eregi () (replaced by preg_match () and 'I' modifier)
Eregi_replace () (use preg_replace () in combination with the 'I' modifier)
Set_magic_quotes_runtime () and its alias function magic_quotes_runtime ()
[Color = olive] session_register () (use $ _ SESSION to replace all variables)
Session_unregister () (use $ _ SESSION to replace all variables)
Session_is_registered () (use $ _ SESSION to replace all variables)
Set_socket_blocking () (use stream_set_blocking)
Split () (use preg_split () instead)
Spliti () (replaced by preg_split () and 'I' modifier)
SQL _regcase ()
Mysql_db_query () (replace mysql_select_db () with mysql_query)
Mysql_escape_string () (use mysql_real_escape_string)
The name of the region passed by the string is discarded. use the LC _ * series constant instead.
The is_dst parameter of mktime (). it is replaced by the new time zone handler.

The main function migration involved is as follows:
Delete function define_syslog_variables reference delete reference to function define_syslog_variables use constant LOG_USER, LOG_USER ,... Substitution
Ereg and eregi functions replace these functions with the preg_match function. int ereg (string $ pattern, string $ string [, array & $ regs]) int eregi (string $ pattern, string $ string [, array & $ regs]) intpreg_match (string $ pattern, string $ subject [, array & $ matches [, int $ flags [, int $ offset]) although the first parameter of the three is a string that represents a regular expression, preg_match uses PCRE (Perl-compatible regular expression syntax): the two ends of the regular expression use a symbol as the boundary, for example, "/pattern/" or "# pattern #", eregi is case-insensitive. For preg_match, the first parameter is case-sensitive, such as "/pattern/I" or "# pattern # I ", the matching data structure returned by the third parameter is different. After the third parameter of ereg is called, an array of complete and sub-matched strings is returned. Preg_match returns a two-dimensional array, which is equivalent to the string in the string array of ereg. the string in preg_match is an array that stores the matching values and locations respectively. If you want to perform multiple matches, PHP provides the preg_match_all function, and the return value of the third parameter is a three-dimensional array.
The ereg_replace and eregi_replace functions use the preg_replace function or the str_replace function to replace the preg_match function with the previous ereg. The first parameter must be converted, and a symbol is added at the beginning and end, for example: "/pattern/" or "# pattern #",... Replace eregi_replace to preg_replace, and add the regular expression parameter after the first parameter. For example, "/pattern/I" or "# pattern # I ",... If the first parameter of ereg_replace is not a regular expression, replace it directly with str_replace.
The spliti function replaces the split string with the explode function or the preg_split function. if you do not need to use a regular expression, it is best to replace explode with the fastest speed. if you use a regular expression to split a string, use the preg_split function instead. The substitution process is similar to ereg/ereg_replace. it is only used in the first regular expression parameter to add a PCRE separator before and after the split regular expression.

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.