PDA

View Full Version : Server Resources


jamescover
09-17-2004, 07:18 AM
What are we talking about in terms of server resources doing something like this:

<?php

include("vars.php");

echo $docType.$n.$html.$n.$head.$n.$title.'Page Title'.$xtitle.$n.$xhead.$n.$body.$bgColor.'"#FFFFFF"'.$tMargin.'"0"'.$mHeight.'"0"'.$lMargin.'"0"'.$mWidth.'"0"'.$gt.$n.$tble.$border.'"0"'.$width.'"775"'.$cSpace.'"0"'.$cPad.'"2"'.$vAlign.'"top"'.$align.'"center"'.$style.'"font-family:arial;font-size:12px;font-weight:bold;"'.$gt.$n.$tRow.$n.$tData.$cSpan.'"8"'.$gt.$text.'USED CAR INVENTORY'.$xtData.$n.$xtRow.$n.$tRow.$n.$tData.$cSpan.'"8"'.$bgColor.'"#DDDDDD"'.$gt.$text.'SHOWING VEHICLES # _ OF # _'.$xtData.$n.$xtRow.$n.$tRow.$n.$tData.$cSpan.'"8"'.$gt.$img.'"images/spacer.gif"'.$name.'"spacer"'.$border.'"0"'.$width.'"1"'.$height.'"25"'.$alt.'"spacer.gif"'.$gt.$xtData.$n.$xtRow.$n.$tRow.$n.$form.$name.'"oFrm1"'.$meth.'"get"'.$act.'"http://www.blah.php"'.$gt.$n.$tData.$gt.$text.'MAKES'.$xtData.$tData.$gt.$sel.$name.'"makes"'.$gt.$n.$opt.$val.'"makes"'.$gt.$text.'Select A Make'.$xopt.$n.$opt.$val.'"make1"'.$gt.$text.'make1'.$xopt.$n.$xsel.$xtData.$xform.$form.$name.'"oFrm1"'.$meth.'"get"'.$act.'"http://www.blah.php"'.$gt.$tData.$gt.$text.'MODELS'.$xtData.$tData.$gt.$sel.$name.'"models"'.$gt.$n.$opt.$val.'"models"'.$gt.$text.'Select A Model'.$xopt.$n.$opt.$val.'"model1"'.$gt.$text.'model1'.$xopt.$n.$xsel.$xtData.$xform.$form.$name.'"oFrm1"'.$meth.'"get"'.$act.'"http://www.blah.php"'.$gt.$tData.$gt.$text.'YEARS'.$xtData.$tData.$gt.$sel.$name.'"years"'.$gt.$n.$opt.$val.'"years"'.$gt.$text.'Select A Year'.$xopt.$n.$opt.$val.'"year1"'.$gt.$text.'year1'.$xopt.$n.$xsel.$xtData.$xform.$form.$name.'"oFrm1"'.$meth.'"get"'.$act.'"http://www.blah.php"'.$gt.$tData.$gt.$text.'PRICE'.$xtData.$tData.$gt.$sel.$name.'"price"'.$gt.$n.$opt.$val.'"price"'.$gt.$text.'Select A Price'.$xopt.$n.$opt.$val.'"price1"'.$gt.$text.'price1'.$xopt.$n.$xsel.$xtData.$xform.$n.$xtRow.$n.$tRow.$n.$tData.$cSpan.'"8"'.$align.'"center"'.$style.'"font-weight:normal;font-size:10px;"'.$gt.$text.'Some Text Here..'.$xtData.$xtRow.$xtble.$n.$tble.$border.'"0"'.$bgColor.'"#FFFFFF"'.$width.'"775"'.$cSpace.'"1"'.$cPad.'"4"'.$vAlign.'"top"'.$align.'"center"'.$style.'"font-family:arial;font-size:10px;font-weight:bold;color:#FFFFFF;"'.$gt.$n.$tRow.$n.$tData.$bgColor.'"#415D82"'.$gt.$text.'YEAR'.$xtData.$tData.$bgColor.'"#415D82"'.$gt.$text.'MAKE'.$xtData.$tData.$bgColor.'"#415D82"'.$gt.$text.'MODEL'.$xtData.$tData.$bgColor.'"#415D82"'.$gt.$text.'MILEAGE'.$xtData.$tData.$bgColor.'"#415D82"'.$gt.$text.'STOCK #'.$xtData.$tData.$bgColor.'"#415D82"'.$gt.$text.'PHOTOS'.$xtData.$tData.$bgColor.'"#415D82"'.$gt.$text.'PRICE'.$xtData.$tData.$bgColor.'"#415D82"'.$gt.$text.'LINK'.$xtData.$xtRow.$xtble.$n.$xbody.$n.$xhtml;

?>


The include:

<?php

$docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
$html = "<html>";
$xhtml = "</html>";
$head = "<head>";
$xhead = "</head>";
$title = "<title>";
$xtitle = "</title>";
$body = "<body";
$xbody = "</body>";
$tMargin = " topmargin=";
$lMargin = " leftmargin=";
$mHeight = " marginheight=";
$mWidth = " marginwidth=";
$bgColor = " bgColor=";
$bg = " background=";
$gt = ">";
$tble = "<table";
$xtble = "</table>";
$border = " border=";
$cPad = " cellpadding=";
$cSpace = " cellspacing=";
$vAlign = " valign=";
$align = " align=";
$tRow = "<tr>";
$xtRow = "</tr>";
$tData = "<td";
$xtData = "</td>";
$width = " width=";
$height = " height=";
$cSpan = " colSpan=";
$rSpan = " rowspan=";
$ctr = "<center>";
$xctr = "</center>";
$n = "\n";
$div = "<div";
$xdiv = "</div>";
$id = " id=";
$style = " style=";
$pre = "<pre>";
$xpre = "</pre>";
$p = "<p>";
$xp = "</p>";
$text = "";
$anchor = "<a href=";
$xanchor = "</a>";
$target = " target=";
$bold = "<b>";
$xbold = "</b>";
$img = "<img src=";
$alt = " alt=";
$break = "<br />";
$nbsp = "&nbsp;";
$form = "<form";
$xform = "</form>";
$name = " name=";
$meth = " method=";
$act = " action=";
$input = "<input";
$type = " type=";
$val = " value=";
$size = " size=";
$tArea = "<textarea";
$xtArea = "</textarea>";
$cols = " cols=";
$rows = " rows=";
$wrap = " wrap=";
$sel = "<select";
$xsel = "</select>";
$opt = "<option";
$xopt = "</option>";

?>




...instead of using the typical formatting? The pages seem to render the same, time-wise, either way.

Here's the page this particular script produces:

http://www.ekigroup.com/dbdemo/template.php


-james


-james

fci
09-17-2004, 07:28 AM
that's pretty ugly looking...you actually use that code? I think most templating systems do the exact oppositve of what you're doing.
ie
<table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
<tr>
<td class="nav" align="left"><a class="nav" href="{U_INDEX}">{L_INDEX}</a></td>
</tr>
</table>

<table class="forumline" width="100%" cellspacing="1" cellpadding="3" border="0">
<tr>
<th class="thHead" height="25" valign="middle"><span class="tableTitle">{MESSAGE_TITLE}</span></th>
</tr>
<tr>
<td class="row1" align="center"><form action="{S_CONFIRM_ACTION}" method="post"><span class="gen"><br />{MESSAGE_TEXT}<br /><br />{S_HIDDEN_FIELDS}<input type="submit" name="confirm" value="{L_YES}" class="mainoption" />&nbsp;&nbsp;<input type="submit" name="cancel" value="{L_NO}" class="liteoption" /></span></form></td>
</tr>
</table>


it's known as seperating logic from design.
my example was taken from phpBB.

jamescover
09-17-2004, 08:06 AM
it's known as seperating logic from design.

If I understand your example, I think you mean seperating form/design from content. Else, I don't understand your example. I often use includes for this...

At any rate, they are not the same, because this isn't what you would call a template, just a way of preformatting PHP for HTML output, no character escaping or special formatting required. One way or the other, the main page/template has to be formatted.

I realize this has very limited application, but it comes in handy for quickly producing certain types of [less elaborate] pages.

But my question was what this might cost in server resources...nothing more.



Thanks, for your input.

-james

firepages
09-17-2004, 03:02 PM
to answer the question it wont have a horrible effect on server load (though still higher than 'normal').

it does have a horrbile effect on the eye though ;)
I dont see the difference between typing $head.$xhead and <head></head> , if you want to avoid formatting issues perhaps look at PHP's HEREDOC syntax http://au.php.net/types.string

jamescover
09-17-2004, 06:18 PM
to answer the question it wont have a horrible effect on server load (though still higher than 'normal').

Thanks.


I dont see the difference between typing $head.$xhead and <head></head> ,

Well, first, I've always had trouble with formatting for php's echo/print and javascript's document.write() method, in certain cases...feel like I've wasted too much time trying to escape characters, etc. Single quotes inside of doubles, or visa versa, with a few backslashs thrown in often works for simple bits of markup, but these rules don't always apply, and can become tricky at times, like when scripting scripts, etc.

Second, the whole point is that I don't type out anything, except attribute values and text. And when I do, they are already formatted...I just type between the preformatted quotes. I turned most HTML elements into variables to be used as an include, then I write my code using this:

http://www.ekigroup.com/dbdemo/varCon.html

Enables me to turn out a preformatted page in a matter of minutes. Then it's just copy and paste. And as long as this doesn't put a strain on server resources, I'll continue to use it.


if you want to avoid formatting issues perhaps look at PHP's HEREDOC syntax http://au.php.net/types.string


Thanks for the link. I visit PHP.net often, but have never come across it...will come in handy.


-james