【发布时间】:2011-04-09 10:25:54
【问题描述】:
我有这段代码:
echo preg_replace('/\!(.*)\!/', file_get_contents('${1}'), $str);
它的意思是用感叹号之间指定的文件内容替换所有!...!。但是,它不起作用,因为 ${1} 没有被替换:
Warning: file_get_contents(${1}) [function.file-get-contents]: failed to open stream: No such file or directory
如果我编码:
echo preg_replace('/\!(.*)\!/', '${1}', $te);
一切都很好(即!...! 之间的文本被文本本身替换)。
如何使file_get_contents 中的${1} 也被替换?
【问题讨论】:
标签: php regex replace preg-replace file-get-contents