Reply to Re: opinions on inline server-side code?

Your name:

Reply:


Posted by Toby Inkster on 02/23/06 22:52

John Salerno wrote:

> After doing a little reading (I'm trying to figure out how to in-line
> Python code in my HTML), it seems like a lot of purists think that
> inline code is a bad thing (sort of like inline style). I was wondering
> what you guys think of that, since you are obviously very strict about
> things like style, HTML vs XHTML, etc. (although, I've never heard any
> criticism in this group of inline PHP, for example, such as when I asked
> about it a while back).

PHP (and ASP and others too) is clearly designed to be scattered in little
droplets throughout an HTML file:

<? require_once "myfunctions.php"; ?>
<h1><? print get_title_from_db(); ?></h1>
<div id="content">
<? print get_content_from_db(); ?>
</div>
<!-- and so on -->

And when you just need to add little splashes of dynamicism here and
there, that works fairly well.

However, for larger projects, you'll probably find it easier to do things
the opposite way around:

<?
require_once "myfunctions.php";
$t = get_title_from_db();
$c = get_content_from_db();
printf("<h1>%s</h1>\n", htmlspecialchars($t));
printf("<div id=\"content\">%s</div>\n",
htmlspecialchars($c));
print "<!-- and so on -->\n";
?>

only "dropping out of PHP mode" occasionally, when you have large chunks
of HTML to output (that hasn't come from a database, or been dynamically
generated in any other way).

For my current blog project, I've got about 6000 lines of code so far, and
all of them are PHP, as per the second example. (No plain HTML yet, and
none planned!)

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

[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

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