What goes here? Code Help needed
| From: | Boz | Date: | Mon, 14 Feb 2000 03:54:33 +0000 |
| Subject: | What goes here? Code Help needed | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-10234@lists.php.net to get a copy of this message | ||
I have been wracking my brain over this code till my eyes are burning
anyone got an extra set that can tell me the missing code. The goal is a
very SIMPLE html template variable repalcement. The missing part has got
to be something with variable variable syntax or something but nothing I
have tried is working. Basically all I need at this point is something
to change $repped to the contents of each one of HP_ varibles
Any help welcome.
Template follows code listing
PS This is running on php4b3 and html files are parsed as php
<<<<<<<<<<<<<<<<<<< test.html
>>>>>>>>>>>>>>>>>>>>>>>>>
<?php
function DoTemplate(){
$numargs = func_num_args();
$filename = func_get_arg(0);
$arg_list = func_get_args();
$tempfile = fopen($filename, "r");
while(!feof($tempfile)){
$templine=fgets($tempfile, 255);
for( $i = 0; $i < $numargs; $i++ ) {
$finder = "%%" . $arg_list[$i] . "%%";
SOMEWHERE IN HERE $repped should be equal to the "contents" of the
variable
that is named the same as the name of the element in $arg_list[$i]
through each loop
$templine = ereg_replace($finder, $repped, $templine);
}
print($templine);
}
fclose($tempfile);
}
$HP_bgcolor="BLACK";
$HP_text="WHITE";
$HP_info="some stuff to print";
DoTemplate("test.tpl","HP_bgcolor","HP_text","HP_info");
?>
<<<<<<<<<<<<<<<<<<<<<<<<<<<
end test.html >>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<
test.tpl >>>>>>>>>>>>>>>>>>>>
<html>
<head>
<title></title>
</head>
<body bgcolor="%%HP_bgcolor%%" text="%%HP_text%%">
%%HP_info%%
</body>
</html>
<<<<<<<<<<<<<<<<<<<<<<<<<
end test.tpl >>>>>>>>>>>>>>>>>>>>