A better way to do this search and replace for a template
php, replace
Solution
Yes, you can define array of things you want to replace and another array with things to replace with.
$array1 = array("[{pageTitle}]", "[{menuA}]");
$array2 = array($pageTitle, $menuA);
$template = str_replace($array1 , $array2 , $template);
Problem
I currently do search and replace for a web page template like this: ``` $template = <<<TEMP <html> <head> <title>[{pageTitle}]</title> </head> [{menuA}] [{menuB}] [{bodyContent}] </html> <<<TEMP; ``` The above is placed in a separate file. Then, I do: ``` $template = str_replace("[{pageTitle}]",$pageTitle,$template); $template = str_replace("[{menuA}]",$menuA,$template); $template = str_replace("[{menuB}]",$menuB,$template); $template = str_replace("[{bodyContent}]",$bodyContent,$template); //Some 10 more similar to the above go here. echo $template; ``` The problem is, there are some 15 in total just like the ones above. Is there a better/cleaner/professional way to do this (either the search and replace, or do the entire thing differently). I find this very messy and unprofessional.