I'm not sure when ereg will be deleted, but my bid is PHP 6.0.
Regarding your second problem (translating ereg to preg ) doesn’t seem something difficult, if your application has> 1 million lines, you probably should have resources to force someone to do this work for a maximum of a week, I would grep all instances of ereg_ in your code and configure some macros in your favorite IDE (simple things like adding separators, modifiers, etc.).
I bet most of the 1768 regular expressions can be ported using a macro, and the rest, well, are good pairs of eyes.
Another option would be to write wrappers around the ereg functions, if they are not available, change if necessary:
if (function_exists('ereg') !== true) { function ereg($pattern, $string, &$regs) { return preg_match('~' . addcslashes($pattern, '~') . '~', $string, $regs); } } if (function_exists('eregi') !== true) { function eregi($pattern, $string, &$regs) { return preg_match('~' . addcslashes($pattern, '~') . '~i', $string, $regs); } }
You get the idea. In addition, the PEAR package PHP compatibility can also be a viable solution.
Differences from POSIX Regular Expression
Starting with PHP 5.3.0, the POSIX Regex extension is deprecated. There are a number of differences between POSIX regular expression and PCRE regular expression. This page lists the most famous ones you need to know when upgrading to PCRE.
- PCRE functions require the template to be enclosed in delimiters.
- Unlike POSIX, the PCRE extension does not have special functions for case insensitivity. Instead, it is supported using the template / i modifier. Other template modifiers are also available to change the matching strategy.
- POSIX functions find the longest leftmost match, but PCRE stops in the first valid match. If the string does not match at all it does not matter, but if it matches it can have dramatic consequences for both the resulting match and match the speed. To illustrate this difference, consider the following example from Jeffrey Fridle's Mastering Regular Expressions. Using the template alone (myself)? (self-sufficient)? if the string is correct using PCRE will lead to a match, but using POSIX, the result will be a complete string. Both (sub) match the original string, but POSIX requires the result to be the longest.
Alix axel
source share