[Solved]A newbie question: changing 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
insodoneva
Forum Newbie
Posts: 4
Joined: Mon Jun 07, 2010 7:50 am

[Solved]A newbie question: changing eregi() to preg_match()?

Post by insodoneva »

Please help me with changing eregi() to preg_match().
Here is the code I need to change:

Code: Select all

if ( eregi( 'index.php\?', $row->link ) ) {
                  if ( !eregi( 'Itemid=', $row->link ) ) {
                     $row->link .= '&Itemid='. $row->id;
                  }
               }
             break;
Any help will be appreciated!
Last edited by insodoneva on Mon Jun 07, 2010 2:40 pm, edited 2 times in total.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: A newbie question: changing eregi() to preg_match()?

Post by Jonah Bron »

You're not using any regex, so preg_match() is unnecessary. Use strpos().

Code: Select all

if (strpos($row->link,  'index.php?') !== false) {
                  if (strpos($row->link, 'Itemid=') === false) {
                     $row->link .= '&Itemid='. $row->id;
                  }
               }
             break;
Edit: Oh yeah, huh? :)
Last edited by Jonah Bron on Mon Jun 07, 2010 10:24 am, edited 1 time in total.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: A newbie question: changing eregi() to preg_match()?

Post by markusn00b »

Jonah Bron wrote:You're not using any regex, so preg_match() is unnecessary. Use strpos().

Code: Select all

if (strpos($row->link,  'index.php\?') !== false) {
                  if (strpos($row->link, 'Itemid=') === false) {
                     $row->link .= '&Itemid='. $row->id;
                  }
               }
             break;
You'll want to take out that back-slash, too. ;)
insodoneva
Forum Newbie
Posts: 4
Joined: Mon Jun 07, 2010 7:50 am

Re: A newbie question: changing eregi() to preg_match()?

Post by insodoneva »

10Q so much guys! your wonderful!!! :D :D :D :drunk:
U just saved my crashing site :mrgreen:
Post Reply