Reply to Re: standard coding...

Your name:

Reply:


Posted by Pedro Graca on 01/12/06 03:17

Domestos wrote:
> 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..

The "standard" installation of PHP on Apache *does not* make Apache call
PHP for files with an "html" extension. To make the PHP embedded in
..html work you have to reconfigure the webserver. If you switch server
all your .html pages will stop working until you reconfigure the new
server.

So it's better to make certain pages where PHP is needed have a .php
extension :)

On the other hand, if you have a .php file with no php inside, the
server will call PHP without needing to, making the page (and the
server) slower and wasting resources.

> Obviously this only applies to pages where a mixture of php and html is
> required...
>
> for example... which is better or more standard....
>
> <html>
> <head>
> <title>title text</title>
> </head>
> <body>
> You name is <?php $name?>

You name is <?php echo $name; ?>

> </body>
> </html>
>
> saved as index.html

There's php inside, so save as index.php

> <?php
> echo '<html>';
> echo '<head>';
> echo '<title>title text</title>';
> echo '</head>';
> echo '<body>';
> echo 'Your name is '.$name;
> echo '</body>';
> echo '</html>';
> ?>
>
> saved as index.php

Ugh!

You can also do

<?php
echo <<<HTML
<html>
<head>
<title>title text</title>
</head>
<body>
You name is $name
</body>
</html>
HTML;
?>

and save as foobar.php

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!

[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

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