Saturday, December 3, 2011
How to change PHP's eregi to preg_match
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 — Case insensitive regular expression match
int eregi ( string $pattern , string $string [, array &$regs ] )
This function is identical to ereg() except that it ignores case distinction when matching alphabetic characters.
Case insensitive regular expression.
The input string.
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 will contain the substring which starts at the first left parenthesis; $regs will contain the substring starting at the second, and so on. $regs will contain a copy of the complete string matched.
A good alternative is to use preg_match() function
Now lets talk about preg_match
preg_match — Perform a regular expression match
Searches subject for a match to the regular expression given in pattern.
Now How to replace eregi with preg_match