Re: mixing HTML and PHP code

From: Date: Fri, 12 Jan 2001 02:40:57 +0000
Subject: Re: mixing HTML and PHP code
Groups: php.general 
Request: Send a blank email to php-general+get-34192@lists.php.net to get a copy of this message
> You _actually_ print() or echo() everything you want to send to the > browser? Absolutely. We've replaced every HTML tag we use often with PHP functions. We separate content, style, layout, and logic so using 100% PHP is the best for us. > if you have ever worked in a fast paced production environment, where html > is changed sometimes 5 times a day, digging through hundreds of lines of: > > echo "<input type=\"text\" name=\"hello\" size=\"20\" > value=\"$value\">" > > starts to make you insane. > > speaking as an html author, and a lover of php, _please_: > > <input type="text" name="hello" size="20" > value="<?=$value?>"> > > it makes the code useable. IMHO even better is: input_text('hello', 20, $value); that's how that would appear on our site. We order the parameters logically and include a catch all final parameter that will add text to the HTML tag. > echo "<html>"; > echo "<head>"; > echo "<title>$title</title>"; > echo "<link rel='stylesheet' type='text/css' > href='resources/css/$css.css'>"; > echo "<script src='/resources/js/base_lib.js' > language='javascript'></script>"; > echo "</head>"; > echo "<body bgcolor='#EEEEEE' text='#000000' > link='#003366' alink='#CCCCCC' > vlink='#003366' topmargin='0' leftmargin='0' > marginwidth='0' > marginheight='0'>"; > echo "<table border='0' cellpadding='0' cellspacing='0' > width='100%' > bgcolor="#000000">"; > echo "<tr>"; > echo "<td valign='top'><img src='resources/images/binarycloud/tmpl/fire.jpg' > alt='' width='466' height='161' > border='0'></td>"; > echo "</tr>"; > echo "</table>"; > > it introduces a whole world of unnecessary complexity. > > to prove my point: > > get one of your friends that knows html but not PHP to look at the above, > then this: > > <html> > <head> > <title><?=$title?></title> > <link rel="stylesheet" type="text/css" > href="resources/css/<?=$css?>.css"> > <script src="/resources/js/base_lib.js" > language="javascript"></script> > </head> > <body bgcolor="#EEEEEE" text="#000000" link="#003366" > alink="#CCCCCC" > vlink="#003366" topmargin="0" leftmargin="0" > marginwidth="0" > marginheight="0"> > <table border="0" cellpadding="0" cellspacing="0" > width="100%" > bgcolor="#000000"> > <tr> > <td valign="top"><img > src="resources/images/binarycloud/tmpl/fire.jpg" > alt="" width="466" height="161" > border="0"></td> > </tr> > </table> On our site that would more like: (comments) (include files) (page specific variables) html(); head($title); head_css('stylesheet.css'); head_script('script.js); x('head'); body($style) table(0, 0, 0, '100%', '', BLACK); tr('top'); td(); image('fire.jpg'); x('td'); x('tr'); x('table'); x('body'); x('html'); Well it would be a bit different because we have other logic and comments throughout, but you get the "jist" of it. BTW "image()" calls "img()" but adds the appropriate image directory to the path. img() is a function that creates the img HTML tag along with automatically finding out and adding the width and height parameters. I can't imagine going back to manually editing those every time I change the image dimensions. We have many people who contribute to this site. Some of them are content editors with no technical expertise. Simply saying "saty away from code in (these) tags" is not enough. 1.they don't have the HTML know how 2. I'm not risking even that much access. They don't go anywhere near an editor or FTP program, they do everything through interfaces we (the tech team) builds. ............. Jade Ohlhauser [website architect]........... http://bandwidthplace.com

« previous php.general (#34192) next »