I'm having a problem with preg_replace... it's placing all the replacements at the top of the string and not where they should be... where the replacements should be it's putting 1's instead.
$search = '/\<global_template=\"(.*?)\"\>/e' ;
$replace = 'include("./global_template/$1.tpl")';
$file = preg_replace($search, $replace, $file) ;
echo $file ;
the global template files each just contain one word, header, navigation, and footer, so it's getting them correctly (see below).
here's the code of $file, which is loaded through file_get_contents:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>{$CONFIG['site_name']}</title>
</head>
<body>
<global_template="header">
<global_template="navigation">
<% SOURCE %>
<global_template="footer">
</body>
</html>
here's what it's outputting right now:
Content-type: text/html
X-Powered-By: PHP/4.3.10
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
headernavigationfooter<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>{$CONFIG['site_name']}</title>
</head>
<body>
1
1
<% SOURCE %>
1
</body>
</html>
as you can see, the problem is not that it's getting the right templates, it's just not putting them in the right place.
It should be putting them where the 1's are.
I was also wondering how to make it insert a newline above the replacement... I tried \n but it doesn't seem to work too well with preg_replace.
Thanks! 🙂