php - A better way to do this search and replace for a template -


i search , replace web page template this:

$template = <<<temp <html> <head> <title>[{pagetitle}]</title> </head> [{menua}] [{menub}] [{bodycontent}] </html> <<<temp; 

the above placed in separate file.

then, 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 above go here. echo $template; 

the problem is, there 15 in total ones above.

is there better/cleaner/professional way (either search , replace, or entire thing differently). find messy , unprofessional.

yes, can define array of things want replace , array things replace with.

$array1 = array("[{pagetitle}]", "[{menua}]"); $array2 = array($pagetitle, $menua);  $template = str_replace($array1 , $array2 , $template); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -