如何使用file_get_contents()获取preg_replace来替换html中的双支撑分隔符?

I am able to get the preg_replace function to find and replace only the inner braced delimiter. eg: the script below replaces { FIELD: date } with "12/12/2015" but leaves the outer braces.

I tried escaping the outer braces to no avail. Help please!

$myFileToCopy = file_get_contents("http://localhost/templatemaker/masterTemplates/".$object['fileName'].$object['fileExtension']);


$myFileToCopy =  preg_replace("{{ FIELD: date }}", "12/12/2015", $myFileToCopy);

You aren't in need of a regex here given your example so str_replace, http://php.net/str_replace, should suffice.

$myFileToCopy = file_get_contents("http://localhost/templatemaker/masterTemplates/".$object['fileName'].$object['fileExtension']);
$myFileToCopy = str_replace("{{ FIELD: date }}", "12/12/2015", $myFileToCopy);

If you wanted to do it with a regex you could try,

$myFileToCopy = file_get_contents("http://localhost/templatemaker/masterTemplates/".$object['fileName'].$object['fileExtension']);
$myFileToCopy =  preg_replace("~\{\{ FIELD: date \}\}~", "12/12/2015", $myFileToCopy);

Note the ~, these are delimiters, http://php.net/manual/en/regexp.reference.delimiters.php, which lets PHP know where the expression starts and ends.