This function eregi has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
Now what we need is to replace the eregi functions used in our old applications with some new functions that are still not depreciated...
First i will describe functionality of eregi() and then i will go for appropriate function to replace it.
eregi():
eregi — Case insensitive regular expression match
Syntax:
int eregi ( string $pattern , string $string [, array &$regs ] )
This function is identical to ereg() except that it ignores case distinction when matching alphabetic characters.
Parameters
pattern
Case insensitive regular expression.
string
The input string.
regs
If matches are found for parenthesized substrings of pattern and the function is called with the third argument regs, the matches will be stored in the elements of the array regs.
$regs[1] will contain the substring which starts at the first left parenthesis; $regs[2] will contain the substring starting at the second, and so on. $regs[0] will contain a copy of the complete string matched.
return Values
Returns the length of the matched string if a match for pattern was found in string, or FALSE if no matches were found or an error occurred.
If the optional parameter regs was not passed or the length of the matched string is 0, this function returns 1.
A good alternative is to use preg_match() function
Now lets talk about preg_match
preg_match — Perform a regular expression match
Description
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int$offset = 0 ]]] )
Now How to replace eregi with preg_match
|
You will need to change three things
- need to add pattern delimiters (can be any character, but most commonly a forward slash)
- [[:alnum:]] will need to be replaced with the PCRE equivalent
- The "i" in "eregi" means case-insensitive, which PCRE does with a flag, specifically the
i flag.
Otherwise, the rest looks PCRE compatible (yes, that's kind of redundant =P)
"/^[a-z0-9][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i"
|