Forum Moderators: coopster
$mystr = file_get_contents("somepagedesign.html");
eval("\$mystr = \"$mystr\";");
echo $mystr;
$ip="127.0.0.1";
$ua="Internet Explorer 7.0";
<p>Your IP address is: $ip<br>Your user-agent is: $ua
Your IP address is: 127.0.0.1
Your user-agent is: Internet Explorer 7.0
Code and HTML all mixed together is something I've always disliked about how most implement their PHP code and sites.
It is output as soon as it is encountered (it's not stored anywhere new), and the processor should know how to format it as the PHP code is already been interpreted before execution.
t's almost impossible not to have some sort of programming logic in templates
Code and HTML all mixed together is something I've always disliked about how most implement their PHP code and sites.
The problem with just stripping it out is if a user has a legitimate reason for using that text, they can become frustrated. I've bumped into it on forums before, and it's really, really annoying.
eval("\$mystr = \"$mystr\";");
The author can be place that code between a couple of tags in the identifying it as code
Let me ask you this, though. If you needed to populate in the html page a table with data from a database, how would you go about doing it using your method and still separate the content from the programming logic?
I prefer to parse the files line by line to sub out the variable chunks.
"<!-- tagname="menu" --!>" PrintTemplateTag("header");
PrintTemplateTag("body");
for( x=1; x<11; x++; ) {
$list_item="This is line #" . x;
PrintTemplateTag("list");
}
PrintTemplateTag("footer"); What if I want to conditionally format the tables?
The point being, there is no simple, clean way to do this.
<!-- tagname="itemlist --!>
<table>
<tr><td>$title</td></tr>
<tr><td>$rowdata</td></tr>
</table> PrintTagnameTable("itemlist",table_start);
$title="whatever";
PrintTagnameTable("itemlist",1);
for( x=1; x<11; x++; ) {
$rowdata="This is data row " . $x;
PrintTagnameTable("itemlist",2);
PrintTagnameTable("itemlist",table_end); where it's just a name in square brackets, that could cause issues coupled with your sanitisation.
while(preg_match('/\!v\{([A-Z_\d]+)\}v\!/sm', $html, $match)) {
if(!isset($vars[$match[1]])) {continue;}
$html = str_replace($match[0], $vars[$match[1], $html);
}
My class that prints stuff can call out each row of a table by line number or if you want to insert comments between the row, by name. When the PrintTagnameTable() function is first called it extracts the entire table into a buffer and explodes the rows into an array, therefore repeated printing of rows is very fast, thus giving the same working functionality without putting tables in separate files.
<table>
!c{loop:SOME_VAR_NAME}c!
<tr>
<td>!v{SUB_VAR_1}v!</td>
<td>!v{SUB_VAR_2}v!</td>
</tr>
!c{endloop:SOME_VAR_NAME}c!
</table>
$vars['SOME_VAR_NAME'] = array(
array(
'SUB_VAR_1' => 'a',
'SUB_VAR_2' => 'b'
),
array(
'SUB_VAR_1' => 'c',
'SUB_VAR_2' => 'd'
),
array(
'SUB_VAR_1' => 'e',
'SUB_VAR_2' => 'f'
)
);
it's got me thinking of something along the lines of...
They increase overhead in general
With templates the code maybe more manageable but it splits over multiple files and takes longer to debug or change something.
I find it hard to believe any web apps are mission critical services requiring perfect optimization with virtually no overhead.
Don't see how this would be any different if you were to roll your own.
This to me seems to contradict itself. If code it more manageable, how does it become harder to manage? ;)
using a well known templating framework such as Smarty allows someone who is unfamiliar with your website to come in and just start making changes.