ereg - template HTML
| From: | Jim Carey | Date: | Fri, 20 Oct 2000 13:05:35 +0000 |
| Subject: | ereg - template HTML | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21371@lists.php.net to get a copy of this message | ||
Hi,
I have an array eg
$a[test] = "value1";
$a[test1] = "value2"; etc
I would like to be able to take the names in the array and find where those
names are used in an html file and then substitute the value (ie value1 and
value2) into the element identified with {{ }} around it - a std template
type of approach.
<input type=text name=test value='{{test}}'>
<input type=text name=test1 value='{{test1}}'> etc
becomes:
<input type=text name=test value='value1'>
<input type=text name=test1 value='value2'>
in Perl I could do it something like (where $HTML is the array and template
points to the template I want to fill in):
open (FILE, "<$template") or die "Couldn't open $template: $!\n";
while (<FILE>)
{
s/{{(.*?)}}/$HTML->{$1}/g;
$content .= $_;
}
close FILE;
return $content;
I guess what I am looking for is the appropriate ereg(?) statement to
achieve the above - hope someone can help ?
cheers
Jim Carey