-1

Possible Duplicate:
Converting ereg expressions to preg

I've tried this a number of different ways and I've even downloaded the Regular Expression reference sheet from addedbytes.com, but I just can't figure out how to move this eregi_replace() statement into a preg_replace() statement.

I've read and understood the delimiter requirements for preg_replace(), but I think the problem is the modifiers. How to I know which modifier to use for this function? I've tried \A, \b, and \e, but none seem to work. I think there's something simply I'm missing.

$bodytag = '%%BODY%%';
$header = eregi_replace($bodytag . '.*', '', $temp);
$footer = eregi_replace('.*' . $bodytag, '', $temp);

I've tried the following:

$header = preg_replace('/%%BODY%%.*/i', '', $temp);
$footer = preg_replace('/.*%%BODY%%/i', '', $temp);

But it doesn't seem to work. What am I missing?

EDIT

More recently, I've tried this with no fix.

$bodytag = "%%BODY%%";
$header = preg_replace("/".$bodytag."(.*)/i", '', $temp);
$footer = preg_replace("/(.*)".$bodytag."/i", '', $temp);
Community
  • 1
  • 1
Hummdis
  • 57
  • 5

2 Answers2

1

SOLVED:

This turned out to be the solution:

$header = preg_replace("/".$bodytag."(.*)/is", '', $temp);
$footer = preg_replace("/(.*)".$bodytag."/is", '', $temp);

Got help and the answer from another website's forum. I was missing the "s" modifier and I also wasn't aware that the modifiers could be stacked.

Hummdis
  • 57
  • 5
0

$header = preg_replace('/BODY(.*)/i', '', $temp); $footer = preg_replace('/(.*)BODY/i', '', $temp);

sandino
  • 3,813
  • 1
  • 19
  • 24
  • I'm sorry, but that doesn't work in the same way that eregi_replace() performs the process. Additionally, I need the "%%" symbols to be there since it's replacing the %%BODY%% string in the theme template with the actual contents of the page body. Furthermore, what are the parenthesis for (why do I need them)? I'm not asking for someone to just give me the answer, just explain what I'm doing wrong. I'm tired of the depreciated messages in my logs. Thanks! – Hummdis Jul 15 '11 at 06:20