Re: [PHP4BETA] What goes here? Code Help needed
| From: | Teodor Cimpoesu | Date: | Mon, 14 Feb 2000 17:27:34 +0000 |
| Subject: | Re: [PHP4BETA] What goes here? Code Help needed | ||
| References: | 1 2 3 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-10257@lists.php.net to get a copy of this message | ||
Boz wrote:
>
> Teodor Cimpoesu wrote:
>
> > > $templine = ereg_replace($finder, $repped, $templine);
> > [snip]
>
> Nope still wont give me the contents of the HP_ variables even if I change
> the passing of the variable to the function to \$HP_info and so on and change
> the string to %%$HP_info%% in the template
> Thanks for the guess though
Now this is a real guess-hit :-)
[tested and it worked!]
<?php
function DoTemplate()
{
$numargs = func_num_args();
$filename = func_get_arg(0);
$arg_list = func_get_args();
$tempfile = fopen ($filename, "r") or die ("horror");
$patterns = array ();
$replaces = array ();
for( $i = 1; $i < $numargs; ++$i ) {
$patterns[] = "|%%" . $arg_list[$i]."%%|";
$replaces[] = $GLOBALS[$arg_list[$i]];
}
while ( $templine = fgets($tempfile, 1024) ) {
$templine = preg_replace($patterns, $replaces, $templine);
print ($templine); /* you can cache this eventually*/
}
fclose ($tempfile);
}
$HP_bgcolor="BLACK";
$HP_text="WHITE";
$HP_info="some stuff to print";
DoTemplate("test.tpl","HP_bgcolor","HP_text","HP_info");
?>
--
CIMPOESU Teodor, Web Programmer
@ DIGICOM S.A. Bucharest, Romania
@ Internet, site development
@ teo@digiro.net , +(401)-330.47.28
official home page ~ http://www.digiro.net/
Internet web page ~ http://internet.digiro.net/