我需要对字符串中的所有PHP标记以及位于PHP标记之间的任何字符执行preg_replace。正则表达式帮助(PHP,preg_replace)
例如,如果文件内容是:
Hey there!
<?php some_stuff() ?>
Woohoo!
所有这一切应交由是:
Hey there!
Woohoo!
这里是我的代码:
$file_contents = file_get_contents('somefilename.php');
$regex = '#([<?php](.*)[\?>])#e';
$file_contents = preg_replace($regex, '<<GENERATED CONTENT>>', $file_contents);
FAIL。
我的正则表达能力很差,有人可以修复我的正则表达式。谢谢。
谢谢,thomasrutter,已经工作。 – Callum 2010-08-05 05:54:47