Jump to content

[SOLVED] Arrays


Unholy Prayer

Recommended Posts

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
Share on other sites

Guest prozente

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
Share on other sites

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
Share on other sites

Guest prozente

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.