| include vs. str_replace a lot of people will include a header and footer on their pages and just have the content in the middle be different, or do content includes. i found a way thats in my opinion is twice as clean. make a file called layout.html, and where you want certian things to be put [Menu], [Content], [Poll] etc. then in your index.php file use the following script at the bottom:
$layout = implode("", file("layout.html"));
$layout = str_replace("[Menu]", $menu, $layout);
$layout = str_replace("[Content]", $content, $layout);
$layout = str_replace("[Poll]", $poll, $layout);
echo $layout;
that way if you decided to change your layout you dont have to worry about forgeting to close of a certian html tag, it'll be right in front of you. what do you guys think of this tip? |