Reply to Re: Article on mixing php and html

Your name:

Reply:


Posted by Oli Filth on 01/12/06 03:21

Domestos said the following on 12/01/2006 00:08:
> Hi all,
>
> I was wondering if there is a standard when mixing PHP and HTML script on a
> page... and if there were any articles on this subject...
>
> i.e. do I make every page a .php page on my website and echo html when I
> need to or...
>
> should I make every page html and embed php when I need to..

Personally, I do neither (except for quick and dirty scripts). As NC
mentioned, separation of presentation and logic is important in any
non-trivial application, so I use a custom template-based system to
render my HTML. e.g.:

example.html
============
<html>
<head>
<title>{TITLE}</title>
</head>
<body>
Your name is {NAME}.
{DOGS?}I really like dogs.{/DOGS?}
{~DOGS?}I really hate dogs.{/~DOGS?}
</body>
</html>


index.php
=========
<?php
include "../includes/template.inc.php";

$values = array("TITLE" => "An interesting page",
"NAME" => "Harold Shipman",
"DOGS?" => true);
$output = render("../templates/example.html", $values);
echo $output;
?>


Advantages include:
* Greater clarity, neatness and legibility of both HTML and PHP code;
and no sodding about with escape characters.
* Localised "entry" point into HTML rendering - one function call does
it all.
* It's obvious where to change variable values, no sodding about hunting
through a mish-mash of PHP and HTML to change things.


--
Oli

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация