Re: AGAIN: [PHP] extracting words from templates

From: Date: Tue, 22 Aug 2000 21:59:01 +0000
Subject: Re: AGAIN: [PHP] extracting words from templates
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-13035@lists.php.net to get a copy of this message
Well I'll be damned!!! I didn't see that there was 'preg_replace()'. It's not in the 'Professional PHP Programming" book and when glanced through the online manual I thought the it was for some sort of print function that printed the changed expression. Man do I feel like such an idiot :o) The 'p' stood for PERL ......... DUH, I'm a programmer, yep, uh huh..... :o) jeeeeeez Thanks Dean, next time I'll open my eyes wider and read a little more. Man, I can't believe this.... Dean Hall wrote: > > 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 > > > > > > > > > > > > -- James Brown, Sr. CIO | DNS/System/Network Administrator Sys-Admin@CSUinternet.net | CSU internet, inc. - Tifton, GA.

« previous php.general (#13035) next »