Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable tags in templates

Status
Not open for further replies.
Jul 28, 2005
358
FR
Hi,

I've seen scripts (one was an encoded one I had to do some work with) that have variable tags in the template so that all you have to do to display certain things is put <%tagname%>.

Obviously this is set up somewhere in the encoded files I have had to work with but how do you code this yourself in your own scripts?

I suppose an example would be if I had a variable with the name $foo how would I code that so if I put <%foo%> I would display the value of $foo.

Thanks in advance.

Richard
 
Hmm, not too sure if that is it.

The templates in question are pure html and just have <%tagname%> in them which then displays the value of the tag.

Unless I'm missing something (which is altogether possible!!) preg_replace wouldn't be used for this.

Thanks anyway.

Richard
 
well, it seemed like a possibly candidate: ave a play.
Code:
<?php
$filename = "content";
$handle = fopen($filename, "r");
$template_content = fread($handle, filesize($filename));
$value1='<font size=10 color=red>';
$value2='</font><hr><br><hr>';
$foo="this is a test";
$search=array(
        '/<%tagname1%>/',
        '/<%tagname2%>/',
        '/<%tagname3%>/'
);

$replace=array(
        ''.$value1.'',
        ''.$value2.'',
        ''.$foo.''
);
$output=preg_replace($search,$replace,$template_content);
echo $output;

?>


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
could you be talking about apache server side includes (SSI). These use similar tags (infact html comments).

but if you want a templating system (or simple tag replacement), i'd always go for php and a system like KarveR's (although i'm not a fan of preg_replace - i'd prefer something like str_replace: largely because i'm not bright enough to understand regular expressions).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top