Re: Help! What about this method to separate HTML code from PHP code?

From: Date: Sat, 24 Aug 2002 13:56:50 +0000
Subject: Re: Help! What about this method to separate HTML code from PHP code?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-113931@lists.php.net to get a copy of this message
For large chunks of HTML, yes I include them, as you have bellow. But if all you're worried about is avoiding this: > <? > echo "<html>"; > echo "<body>"; > echo "This is a example file!"; > echo "</body>"; > echo "</html>"; > ?> .. you can skip in and out of PHP whenever you like... think of it more as "php is inside a HTML document", not "HTML is inside a PHP document"... consider this: <? // some PHP stuff $mytitle = "This is the title of my page"; ?> <html> <head> <title><?=$mytitle?></title> </head> <body> This is a example file! <? // some more php stuff echo "my dogs name is Gizmo"; ?> </body> </html> The whole document can be a mixture of PHP and HTML. My document template is usually something like: <? include('inc/config.inc'); // config vars include('inc/sessions.inc'); // maybe a session library or whatever include('template/html_header.inc'); // contains everything from HTML > BODY ?> This is my page content <? include('template/html_footer.inc'); // stuff to wrap up the page ?> Justin French on 24/08/02 7:41 PM, jianking (compmen@hotmail.com) wrote: > Help! What about this method to separate HTML code from PHP code? > > I don't like the HTML code in the PHP code. So I put them in a file. > > For example: > > <====the old file====> > > <---index.php---> > > <? > echo "<html>"; > echo "<body>"; > echo "This is a example file!"; > echo "</body>"; > echo "</html>"; > ?> > > <====method====> > > I put the HTML code into a file, and use it by "include" or "require". > > <---index.html.php---> > > <html> > <body> > This is a example file! > </body> > </html> > > <---index.php---> > > <? > include "index.html.php"; > ?> > > Can you tell me this method is good? > If not, please tell me the best method! > Thank you!!!

« previous php.general (#113931) next »