Jump to content


Photo

eregi to preg_match


  • Please log in to reply
3 replies to this topic

#1 Monkeymatt

Monkeymatt
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 14 June 2006 - 01:20 AM

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

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

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

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

Any help would be appreciated.

Monkeymatt

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 14 June 2006 - 01:35 AM

I am not familiar with ereg, but what is your problem?

I mean, what are you trying / failing to do?
~ D Kuang

#3 Monkeymatt

Monkeymatt
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 14 June 2006 - 01:49 AM

$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.

#4 Wildbug

Wildbug
  • Members
  • PipPipPip
  • Advanced Member
  • 1,149 posts

Posted 16 June 2006 - 07:34 PM

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).

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

Twice a day my clock works PERFECTLY!  I can't figure out what's wrong with it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users