Page 1 of 1

eregi to preg_match

Posted: Fri Apr 15, 2011 4:40 pm
by qwik
Hi, I would like to transfer eregi in this code:

Code: Select all

	if ( eregi( 'index.php\?', $row->link ) ) {

        				if ( !eregi( 'Itemid=', $row->link ) ) {

        					$row->link .= '&Itemid='. $row->id;

        				}

        			}
to preg_match, because I am getting errors like:

Deprecated: Function eregi() is deprecated in C:\wamp\www....

Any help is appreciated.

Re: eregi to preg_match

Posted: Fri Apr 15, 2011 9:39 pm
by Zlobcho
Hi,

Your ereg regex is very simple

Code: Select all

if (preg_match('/index\.php\?/i', $row->link)) {
    if (!preg_match('/itemid\=/i', $row->link)) {
        $row->link .= '&Itemid='. $row->id;
    }
}
You do not need both if's, they can be combined into one with && :)

Re: eregi to preg_match

Posted: Sat Apr 16, 2011 2:48 pm
by qwik
Thanks man, it's working perfect!