php - How do I get preg_replace to replace double braced delimiters in html using file_get_contents()? -


i able preg_replace function find , replace inner braced delimiter. eg: script below replaces { field: date } "12/12/2015" leaves outer braces.

i tried escaping outer braces no avail. 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 regex here given example 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 wanted regex try,

$myfiletocopy = file_get_contents("http://localhost/templatemaker/mastertemplates/".$object['filename'].$object['fileextension']); $myfiletocopy =  preg_replace("~\{\{ field: date \}\}~", "12/12/2015", $myfiletocopy); 

note ~, these delimiters, http://php.net/manual/en/regexp.reference.delimiters.php, lets php know expression starts , ends.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -