Salis Posted May 30, 2007 Share Posted May 30, 2007 All right. I'm not sure how to explain this but.... I am working on a web site that allows members to "custom" design their own profile template. I pulled this idea from phpbb forums where there are values in the database and in the template you have, for an example, {POSTER_NAME}. When some one reads the page, the server (some how, and this is were i need help) read the template and replaces {POSTER_NAME} with the corresponding value then sends it to whom ever requested it. Quote Link to comment Share on other sites More sharing options...
chrisprse Posted May 30, 2007 Share Posted May 30, 2007 Hi You can make use of the "str_replace" function for this... http://uk2.php.net/str_replace Chris. Quote Link to comment Share on other sites More sharing options...
Salis Posted May 30, 2007 Author Share Posted May 30, 2007 I was thinking that, but my concern with that is load time and bandwidth. I would have to open the file, read the text (clean it for any hacking code), replace it then echo it. I've seen some fast phpbb boards with a lot of text but I'm not sure if this is how the phpbb boards work or not. But I'll give it a shot thanks. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 30, 2007 Share Posted May 30, 2007 assuming you know how to do a select in mysql, I will skip that to actually displaying content... Very simple. <?php $sql = mysqli_query($db,"SELECT * FROM table WHERE id='$someuser'"); $row = mysqli_fetch_array($sql); echo $row['userName']; //This is one field in the table that contains the users name echo $row['pageContent']; //This is another filed in the table that contains the content ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted May 30, 2007 Share Posted May 30, 2007 www.google.com easy template system OR smarty Both are very good template engines. Quote Link to comment Share on other sites More sharing options...
Salis Posted May 30, 2007 Author Share Posted May 30, 2007 I hope to clear a little up. Below is an example of what will go on. <? // connect to the database define("My_SITE",true); require("includes/sql_connection.php"); include("includes/functions.php"); $Clean = new CleanStr; $Mem_Query = mysql_query("SELECT * FROM members WHERE mname='".$Clean->MQur($_GET['member'])."'"); $Mem_Array = mysql_fetch_array($Mem_Query); if( empty($Mem_Array['mname']) ) { // Want to include a "No Member Found" notice } else { $tpl_replace = array('{MEMBER_NAME}'=>$Mem_Array['mname'], '{MEMBER_AVATAR}'=>$Mem_Array['avatar'], '{MEMBER_BIO}'=>$Mem_Array['bio']); //want to include the template here then replace array_keys with array_values as above } ?> OK, you see $tpl_replace right. Well what I want to do is read the contents of the template ant replace the keys with the values. I don't want the template to include any php for security reasons, however I want to use this approach so that my members will be able to create a template for them selves. Does this help explain it a bit better? My goal is to not only offer a web site that it's members can customize, but also a site that I design with no 3rd party programs. Quote Link to comment Share on other sites More sharing options...
per1os Posted May 30, 2007 Share Posted May 30, 2007 Ive tried that too, as long as you do not need to loop through data etc it is straight forward, or if you do it should be done before the parse. <?php // connect to the database define("My_SITE",true); require("includes/sql_connection.php"); include("includes/functions.php"); $Clean = new CleanStr; $Mem_Query = mysql_query("SELECT * FROM members WHERE mname='".$Clean->MQur($_GET['member'])."'"); $Mem_Array = mysql_fetch_array($Mem_Query); if( empty($Mem_Array['mname']) ) { // Want to include a "No Member Found" notice } else { $tpl_replace = array('{MEMBER_NAME}', '{MEMBER_AVATAR}', '{MEMBER_BIO}'); $tpl_replace_with = array($Mem_Array['mname'], $Mem_Array['avatar'], $Mem_Array['bio']); $template = file_get_contents('template.tpl'); $template = str_replace($tpl_replace, $tpl_replace_with, $template; echo $template; // the above OR you could do it like this. $tpl_replace = array('{MEMBER_NAME}'=>$Mem_Array['mname'], '{MEMBER_AVATAR}'=>$Mem_Array['avatar'], '{MEMBER_BIO}'=>$Mem_Array['bio']); $template = file_get_contents('template.tpl'); foreach ($tpl_replace as $replace => $with) { $template = str_replace($replace, $with, $template); } echo $template; } ?> Both should be fairly quick, I doubt you would see a difference in performance, I my self would prefer the foreach but yea. I think that would work.. Quote Link to comment Share on other sites More sharing options...
Salis Posted May 30, 2007 Author Share Posted May 30, 2007 Ummm.. Hum... wow that easy?! Thanks everyone for your help and support! frost110, file_get_contents() is exactly what I needed! Man, you'd think that with hundreds of php functions, you'd figure the php development team would combine like functions and reduce the function head ache! Again thanks every one. Quote Link to comment 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.