Re: AGAIN: [PHP] extracting words from templates
| From: | Jim Brown, Sr. | Date: | Tue, 22 Aug 2000 19:42:39 +0000 |
| Subject: | Re: AGAIN: [PHP] extracting words from templates | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-13008@lists.php.net to get a copy of this message | ||
I've already known about doing the short hand inside the HTML, that's not what
I'm trying to accomplish but thanks for the refresher :o)
The reason I'm wanting to do it this way is to have a function that replaces
whatever variable (%%...%%) is placed inside the template. I want to allow
people to create their own templates and config file in PHP and have them
reference my PHP script which will replace their values. Not just using it for
my templates.
Does that explain a little better?? I might not have been to clear :o)
Dean Hall wrote:
>
> On Tue, 22 Aug 2000, Jim Brown, Sr. wrote:
>
> > Greetings,
> >
> > I've got a question:
> >
> > What's the best way to extract a word from inside a template variable? If the
> > variable in the template is '%%TITLE%%', how could I just extract
> > 'TITLE' from
> > it so I can make it '$TITLE' in my script which will print the title when I call
> > 'print "<TITLE>$TITLE</TITLE>";'??
>
> I'm sure there's a simple way to loop through the file with regex, but
> I'll make a suggestion based on what I do.
>
> Instead of: <TITLE>%%TITLE%%</TITLE>
>
> Do: <TITLE><?=$TITLE?></TITLE>
>
> <?=$var?> is shorthand for <? echo $var; ?>
>
> It's short and easy; much easier for implementing templates in PHP.
>
> And if you already have implemented it this way, just take my suggestion
> with a grain of salt, and wait for the regex guys to answer.
>
> Dean.
>
> >
> > Here's what I'm doing now:
> >
> > $header = file('includes/header.inc');
> > while (list(,$val) = each($header)) {
> > if (eregi('%%TITLE%%', "$val")) {
> > $title = str_replace('%%TITLE%%', "$TITLE", "$val");
> > echo "$title";
> > }
> > elseif (eregi('%%BGCOLOR%%', "$val")) {
> > $body = str_replace('%%BGCOLOR%%', "$BGCOLOR",
> > "$val");
> > echo "$body";
> > }
> > else {
> > echo "$val";
> > }
> > }
> >
> >
> > TIA
> >
> >
--
James Brown, Sr.
CIO | DNS/System/Network Administrator
Sys-Admin@CSUinternet.net | CSU internet, inc. - Tifton, GA.