eregi to preg_match

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qwik
Forum Newbie
Posts: 2
Joined: Fri Apr 15, 2011 4:34 pm

eregi to preg_match

Post 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.
User avatar
Zlobcho
Forum Newbie
Posts: 18
Joined: Sun Jun 21, 2009 7:57 pm

Re: eregi to preg_match

Post 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 && :)
qwik
Forum Newbie
Posts: 2
Joined: Fri Apr 15, 2011 4:34 pm

Re: eregi to preg_match

Post by qwik »

Thanks man, it's working perfect!
Post Reply