Jump to content

eregi to preg_match


Monkeymatt

Recommended Posts

How do I convert this eregi matching to preg, it works in eregi, but I can't get it to work in preg:

[code]
eregi("<{loop_".$section."}>(.*)<{/loop_".$section."}>", $this->level_tracker[$i]['****code****'], $contents);
[/code]

Here is the preg_match I tried, which does not work:

[code]
preg_match('|<{loop_'.$section.'}>(.*)<{/loop_'.$section.'}>|iU', $this->level_tracker[$i]['****code****'], $contents);
[/code]

Any help would be appreciated.

Monkeymatt
Link to comment
https://forums.phpfreaks.com/topic/11939-eregi-to-preg_match/
Share on other sites

$this->level_tracker[$i]['****code****'] is the data from a template file. I want to be able to pull all the stuff out of between <{loop_(section name)}> and <{/loop_(section name)}> not matter what is in there. Currently, preg is not matching any of the sections for me.
Link to comment
https://forums.phpfreaks.com/topic/11939-eregi-to-preg_match/#findComment-45324
Share on other sites

Two things: Try the 's' modifier so the period (.) matches newlines, too. Secondly, are the curly braces part of the text you're trying to match? If so, try escaping them (although it shouldn't matter -- I bet the newline thing is holding you up).

[code]preg_match(
   '|<{loop_'.$section.'}>(.*)<{/loop_'.$section.'}>|iUs', // <-- note 's' modifier
   $this->level_tracker[$i]['****code****'],
   $contents
);[/code]
Link to comment
https://forums.phpfreaks.com/topic/11939-eregi-to-preg_match/#findComment-46424
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.