Re: pulling in template file in var and populating vars?

From: Date: Thu, 23 Mar 2006 00:36:06 +0000
Subject: Re: pulling in template file in var and populating vars?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-232427@lists.php.net to get a copy of this message
blackwater dev wrote:
I have a chunk of html data that I want to output for each iteration through a db result while($result){ $list.=file_get_contents("my_template_file.php"); } return $list; The template file looks like this: <table>
    <tr>
         <td><?php echo $result["name"];?></td>
    </tr>
</table> I basically want a good way to keep the template file out of the class so I don't have to code: $list.="<table><tr>...etc The problem is with the method I have, it doesn't translate the vars...what's the best way to do this? Thanks! check into the eval() function
I see reading in the user notes that you will want to do something like $filedata = file_get_contents($file); while ($result) { $list .= eval('?>'.$filedata);s } Looks like someone has figured this out. You might also look into using str_replace and use markers in your template file {SOME_VAR} and then set in your while loop $some_var = $result['something']; $list .= str_replace('{SOME_VAR}', $some_var, $filedata); This might work for you also Jim

« previous php.general (#232427) next »