Unholy Prayer Posted April 20, 2007 Share Posted April 20, 2007 I still need help with this code. The variables are being replaced correctly, but I have a file with html content that I am using with the code but the html isn't being displayed, just the variables. This is my code: $array = array( 'FORUM_ID' => $fid, 'FORUM_NAME' => $fname, 'FORUM_DESC' => $fdescription, 'FORUM_STATUS' => $fstatus, 'FORUM_TYPE' => $ftype, 'FLASTPOST_AUTH' => $lastpostauth, 'FLASTPOST_DATETIME' => $lastpostdatetime, 'FORUM_THREADS' => $numthreads, 'FORUM_REPLIES' => $numreplies ); $buildforums = file_get_contents('templates/default/forumlist_body.tpl'); foreach($array as $buildforums) { print $buildforums; } I know the array is correct because on this page, it displays them but without the html tags from forumlist_body.tpl. That file contains html tables and what not but only lists whatever $fid, etc. is equal to even when I only use FORUM_ID to display $fid. Link to comment https://forums.phpfreaks.com/topic/47834-solved-arrays/ Share on other sites More sharing options...
Guest prozente Posted April 20, 2007 Share Posted April 20, 2007 I don't fully understand what you're trying to do. But.. Your code currently stores the contents of ./templates/default/forumlist_body.tpl to $buildforums Then you use foreach to go through your array in which you overwrite your $buildforums variable, I'm guessing you didn't mean to do this. Link to comment https://forums.phpfreaks.com/topic/47834-solved-arrays/#findComment-233727 Share on other sites More sharing options...
Unholy Prayer Posted April 20, 2007 Author Share Posted April 20, 2007 So does this mean I should eliminate my foreach statement? I tried this, but now the arrays don't work. :'( Link to comment https://forums.phpfreaks.com/topic/47834-solved-arrays/#findComment-233728 Share on other sites More sharing options...
Guest prozente Posted April 20, 2007 Share Posted April 20, 2007 Explain what you're trying to do first. Link to comment https://forums.phpfreaks.com/topic/47834-solved-arrays/#findComment-233730 Share on other sites More sharing options...
Unholy Prayer Posted April 20, 2007 Author Share Posted April 20, 2007 Ok the arrays are supposed to replace words in the forumlist_body.tpl file with whatever word matches. For example, 'FORUM_ID' => $fid, will replace whereever the word FORUM_ID is found in the contents of the file forumlist_body.tpl. My script partially does what it's supposed to, but it only displays where FORUM_ID and the other arrays are found but displays whatever $fid is equal to(In this case, it is in a loop that gets the primary key column from the database). There are html tags in forumlist_body.tpl and the strings such as $fid and $fname are supposed to be displayed in a table, but all my script does is display whatever the strings are equal to without the html. Link to comment https://forums.phpfreaks.com/topic/47834-solved-arrays/#findComment-233735 Share on other sites More sharing options...
Guest prozente Posted April 20, 2007 Share Posted April 20, 2007 ok then you'd do something like this $array = array( 'FORUM_ID' => $fid, 'FORUM_NAME' => $fname, 'FORUM_DESC' => $fdescription, 'FORUM_STATUS' => $fstatus, 'FORUM_TYPE' => $ftype, 'FLASTPOST_AUTH' => $lastpostauth, 'FLASTPOST_DATETIME' => $lastpostdatetime, 'FORUM_THREADS' => $numthreads, 'FORUM_REPLIES' => $numreplies ); $buildforums = file_get_contents('templates/default/forumlist_body.tpl'); foreach ($array as $template_var => $replacement_var){ $buildforums = str_replace($template_var, $replacement_var, $buildforums); } echo $buildforums; Link to comment https://forums.phpfreaks.com/topic/47834-solved-arrays/#findComment-233737 Share on other sites More sharing options...
Unholy Prayer Posted April 20, 2007 Author Share Posted April 20, 2007 Omg, thank you! You are my savior of the day. Link to comment https://forums.phpfreaks.com/topic/47834-solved-arrays/#findComment-233741 Share on other sites More sharing options...
per1os Posted April 20, 2007 Share Posted April 20, 2007 ok then you'd do something like this $array = array( 'FORUM_ID' => $fid, 'FORUM_NAME' => $fname, 'FORUM_DESC' => $fdescription, 'FORUM_STATUS' => $fstatus, 'FORUM_TYPE' => $ftype, 'FLASTPOST_AUTH' => $lastpostauth, 'FLASTPOST_DATETIME' => $lastpostdatetime, 'FORUM_THREADS' => $numthreads, 'FORUM_REPLIES' => $numreplies ); $buildforums = file_get_contents('templates/default/forumlist_body.tpl'); foreach ($array as $template_var => $replacement_var){ $buildforums = str_replace($template_var, $replacement_var, $buildforums); } echo $buildforums; Is that not the same thing as I posted here: http://www.phpfreaks.com/forums/index.php/topic,136859.msg578780.html#msg578780 ??? Yes, unless you setup a parsing bit. Code: <?php $tplFileData = '<a href="viewforum.php?id=FORUM_ID">FORUM_NAME</a>'; $fid=1; $array = array("FORUM_ID" => "$fid", "FORUM_NAME" => "Name"); foreach ($array as $key => $val) { $tplFileData = str_replace($key, $val, $tplFileData); } print $tplFileData; ?> Link to comment https://forums.phpfreaks.com/topic/47834-solved-arrays/#findComment-233761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.