unidox Posted July 21, 2008 Share Posted July 21, 2008 Lets say I have an .htm page called page.htm. Inside index.php is this: $template = file_get_contents("page.htm"); $template = str_replace("<{CONTENT}>",include("content.php"),$template); Would that work, or how else would I do it? Link to comment https://forums.phpfreaks.com/topic/115882-str_replace/ Share on other sites More sharing options...
DarkWater Posted July 21, 2008 Share Posted July 21, 2008 No. You'd need to access content.php through the HTTP wrapper. $template = file_get_contents("page.htm"); $template = str_replace("<{CONTENT}>",file_get_contents("http://www.yoursite.com/content.php"),$template); But quite frankly, that's a horrible templating system. Why not use Smarty? Link to comment https://forums.phpfreaks.com/topic/115882-str_replace/#findComment-595813 Share on other sites More sharing options...
unidox Posted July 21, 2008 Author Share Posted July 21, 2008 Can I ask what smarty is? Link to comment https://forums.phpfreaks.com/topic/115882-str_replace/#findComment-595814 Share on other sites More sharing options...
marcus Posted July 21, 2008 Share Posted July 21, 2008 Um, lol, there's a lot easier way of doing it without using Smarty. <?php function tpl($output){ $find = array("<{CONTENT}>","<{FOOTER}>"); $repl = array(file_get_contents("content.php"), file_get_contents("footer.php")); return str_replace($find, $repl, $output); } ob_start("tpl"); echo "<{CONTENT}>"; echo "<{FOOTER}>"; ob_end_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/115882-str_replace/#findComment-595846 Share on other sites More sharing options...
DarkWater Posted July 21, 2008 Share Posted July 21, 2008 Smarty is a lot easier to work with, honestly. It has some pretty nice features and a great cache system. Link to comment https://forums.phpfreaks.com/topic/115882-str_replace/#findComment-595853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.