Php Preg_replace语法在与空格一起使用时不起作用

Php Preg_replace语法在与空格一起使用时不起作用,php,regex,preg-replace,Php,Regex,Preg Replace,我正在尝试对使用file\u get\u contents从文件接收的内容使用preg\u replace preg_replace("/\/\/data(.*?)\/\/enddata/i",$string,$contents); $string = 'data new '; //此处的内容以白色间距显示 $contents = ' //data //enddata'; 事情是preg_replace正在执行但未更新:) 有什么想法吗,伙计们?thnx不匹配换行符,除非您通过添加s

我正在尝试对使用file\u get\u contents从文件接收的内容使用preg\u replace

preg_replace("/\/\/data(.*?)\/\/enddata/i",$string,$contents);

$string = 'data new ';
//此处的内容以白色间距显示

$contents = '



//data
//enddata';
事情是preg_replace正在执行但未更新:)


有什么想法吗,伙计们?thnx不匹配换行符,除非您通过添加
s
修饰符明确告诉它

另外,尝试使用不同的分隔符。我个人喜欢括号,因为它们永远不需要转义,即使模式中有更多的括号:)


使用/有助于在替换后返回值:)

他可能还需要将
preg\u replace
返回值分配给
$contents
。@user1690718
preg\u replace
实际上不会更改
$contents
"(//data(.*?)//enddata)is"