Re: AGAIN: [PHP] extracting words from templates

From: Date: Tue, 22 Aug 2000 19:56:42 +0000
Subject: Re: AGAIN: [PHP] extracting words from templates
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-13011@lists.php.net to get a copy of this message
On Tue, 22 Aug 2000, Jim Brown, Sr. wrote: > 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) > Sure. :-) Just wanted to make sure you weren't a newbie who hadn't RTFM. LOL I know this would be a cinch in Perl, but I'm not too familiar with regular expressions, and even less so withe the regex functions in PHP. Plus, I'm at work and can't browser the manual right now. I'd look through the Perl compatible regular expression functions if I were you. http://www.php.net/manual if my memory is correct. Dean. > > > 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 > > > > > > > >

« previous php.general (#13011) next »