You are here: Re: [PHP] better way to mix html and php code? « PHP « IT news, forums, messages
Re: [PHP] better way to mix html and php code?

Posted by Miles Thompson on 11/16/05 23:17

At 05:04 PM 11/16/2005, Brent Baisley wrote:
>You should separate HTML and PHP code into separate files to make it
>easily maintainable. Ideally, someone who knows HTML without any
>knowledge of PHP would be able to change the layout of the web page
>without breaking anything.
>There are a bunch of examples of how to do this, usually falling
>under the "MVC Design Pattern" title. That's Model, View, Controller.
>
>I use a simple substitution system to embed "tags" that represent
>data into my HTML files.
>
>The html file would look something like:
><table>
><tr><td>First Name</td>
><td>{:FirstName:}</td>
><tr><td>Last Name</td>
><td>{:LastName:}</td>
></table>
>
>The php file would be something like:
>$tpl = file_get_contents('htmlfile.htm');
>//Assign Data to tags
>$data['{:FirstName:}'] = 'Brent';
>$data['{:LastName:}'] = 'Baisley';
>//Get Tags to search on
>$tags = array_keys($data);
>
>//Populate html template with data
>$content = str_replace($tags, $data, $tpl);
>echo $tpl;
>
>
>That's an extremely simplified templating system and an over
>simplified example. But it shows how you can easily completely
>separate html from php, presentation from logic. I find it far easier
>to work on than any of your three examples. Most importantly, it
>allows more talented interface designer design your interface, while
>you focus on the php and logic.
>
<a lot of stuff snipped>

This

><td>{:FirstName:}</td>
is really so different from

<td> <?php echo $FirstName ?> </td>

Why learn a templating language on top of PHP? That's one of its reasons
for being.

Yes, it can be a bit of a hash at times. Of all the suggestion offered, if
I was dumped in and had to do so maintenance, Curt's was the cleanest example.

Cheers - Miles

 

Navigation:

[Reply to this 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

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