开发者

eregi_replace() to preg_replace() help [duplicate]

This question already has answers here: Closed 10 years ago.

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜