atholon Posted February 4, 2008 Share Posted February 4, 2008 I can`t figure this out...does anyone know what I am doing wrong. I am trying to make a place holder but it doesn`t work <?php class MasterPage { var $title; var $bodyHtml; function MasterPage( $pathToHtml, $iTitle) { $this->title = $iTitle; $this->bodyHtml = readfile($pathToHtml); } function Render() { // replace placeholders print($this->bodyHtml); $this->bodyHtml = str_replace('{title}', $this->title, $this->bodyHtml); print($this->bodyHtml); } } ?> The call: // Usage of MasterPage in a real script... (let's say in the /admin/index.php) require('../includes/MasterPage.class'); $page = new MasterPage('../skins/defaultSkin/index.html', 'Admin Menu'); $something = "hey"; $page->Render(); Quote Link to comment https://forums.phpfreaks.com/topic/89315-placeholders/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 4, 2008 Share Posted February 4, 2008 The readfile() function outputs the contents of the file to the browser, it does not return the contents so that you can assign it to a variable. You probably want to use the file_get_contents() function. Quote Link to comment https://forums.phpfreaks.com/topic/89315-placeholders/#findComment-457351 Share on other sites More sharing options...
atholon Posted February 4, 2008 Author Share Posted February 4, 2008 Ok that works... how would I replace the text with an entire function? Like this: function index () { echo (" <table border=\"0\" align=\"center\" valign=\"center\" width=\"90%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"5\">"); echo (" <tr><td valign=\"middle\" width=\"250\">"); echo (" <b>News/Article Options:</b><br>"); echo (" 1. <a href=\"./news.php?view=addnews\" class=\"somethingelse\">Create a new article</a> <br>"); echo (" 2. <a href=\"./news.php?view=list\" class=\"somethingelse\">Manage articles</a> <br>"); echo (" </td>"); echo (" <td valign=\"middle\" width=\"250\">"); echo (" <b>Tutorial Options:</b><br>"); echo (" 1. <a href=\"./tutorials.php?view=submit\" class=\"somethingelse\">Create a new tutorial</a> <br>"); echo (" 2. <a href=\"$_SERVER[php_SELF]?view=addcat\" class=\"somethingelse\">Add a category</a> <br> "); echo (" 3. <a href=\"blank\" class=\"$_SERVER[php_SELF]?view=addsubcat\">Add a subcategory</a><br>"); echo (" 4. <a href=\"../tutorials/tutorials.php?view=theadminscreen\" class=\"somethingelse\">Tutorials waiting to be approved</a> <br> "); echo (" </td></tr>"); echo (" <tr><td valign=\"middle\" width=\"250\">"); echo (" <b>Tutorial Options:</b><br>"); echo (" 1. <a href=\"./tutorials.php?view=submit\" class=\"somethingelse\">Create a new tutorial</a> <br>"); echo (" 2. <a href=\"blank\" class=\"somethingelse\">Add a category</a> <br> "); echo (" 3. <a href=\"blank\" class=\"somethingelse\">Add a subcategory</a><br>"); echo (" </td>"); echo (" <td valign=\"middle\" width=\"250\">"); echo (" <b>Main Page Options:</b><br>"); echo (" 1. <a href=\"$_SERVER[php_SELF]?view=mplinks\" class=\"somethingelse\">Change main page pictures and links</a> <br>"); echo (" </td></tr>"); echo (" <tr><td valign=\"middle\" width=\"250\">"); echo (" <b>Side Options:</b><br>"); echo (" 1. <a href=\"blank\" class=\"somethingelse\">Create a new review</a> <br>"); echo (" 2. <a href=\"blank\" class=\"somethingelse\">Edit existing review</a> <br> "); echo (" 3. <a href=\"blank\" class=\"somethingelse\">Delete review</a><br>"); echo (" </td>"); echo (" <td valign=\"middle\" width=\"250\">"); echo (" <b>User Options:</b><br>"); echo (" 1. <a href=\"blank\" class=\"somethingelse\">Ban user</a><br>"); echo (" </td></tr>"); echo (" <tr><td valign=\"middle\" width=\"250\">"); echo (" <b>File Management:</b><br>"); echo (" 1. <a href=\"$_SERVER[php_SELF]?view=fileupload\" class=\"somethingelse\">Upload a file</a> <br>"); echo (" 2. <a href=\"blank\" class=\"somethingelse\">Erase a file</a> <br> "); echo (" </td>"); echo (" <td valign=\"middle\" width=\"250\">"); echo (" <b>User Options:</b><br>"); echo (" 1. <a href=\"blank\" class=\"somethingelse\">Administrate User Ratings</a><br>"); echo (" </td></tr>"); echo (" </table>"); } Quote Link to comment https://forums.phpfreaks.com/topic/89315-placeholders/#findComment-457359 Share on other sites More sharing options...
atholon Posted February 4, 2008 Author Share Posted February 4, 2008 Would I store it all to one variable? Quote Link to comment https://forums.phpfreaks.com/topic/89315-placeholders/#findComment-457645 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.