Forum Moderators: coopster
Tags will be like -#THIS#-
I've setup a function codemagic() which returns some code in response to a value passed into it, so I can achieve the correct result as follows:
$pagecontent = str_replace('-#header#-',codemagic('-#header#-'),$pagecontent);
$pagecontent = str_replace('-#footer#-',codemagic('-#footer#-'),$pagecontent);
$pagecontent = str_replace('-#other#-',codemagic('-#other#-'),$pagecontent);
However, rather than having a str_replace going on for every section of code I'd like to achieve this with a single str_replace
I'm just hoping someone can point me in the right direction to do this
I'm imagining It'll involve some ereg function but I'm having trouble finding resources to find data between specified characters as opposed to matching an expression
function codemagic($code)
{
switch ($code) {
case '-#header#-':
$code = <<<ENDOFHTML
<head><title>Title</title></head>
ENDOFHTML;
break;
case '-#footer#-':
$code = <<<ENDOFHTML
<p>END OF PAGE</p>
ENDOFHTML;
break;
case '-#other#-':
$code = <<<ENDOFHTML
<body><p>Here is the body!</p></body>
ENDOFHTML;
break;
}
return $code;
}
$pagecontent = <<<ENDOFHTML
<html>
-#header#-
-#other#-
-#footer#-
</html>
ENDOFHTML;
$pagecontent = preg_replace [php.net]('/(-#[^#]+#-)/e', "codemagic('$1')", $pagecontent);
print $pagecontent;