Page 1 of 1

Question reg. PHP include code, recommended formating?

Posted: Wed Jan 14, 2004 12:41 am
by bKeppel
Hi,

I'm a bit new to PHP and the only command I've been using a lot lately is the include command.
Which way should I write my include statement (see below)? Is there a preferred way? Are there any explicit cons/pros with each?

<?php include "header.htm">

<?include "header.htm"; ?>

BTW: I'm using an .htm extension for the header file, as the php extension gave me problems (I'm also using it as a plain frame in another page).

Please let me know. I'm currently using the latter option, and someone accussed my code of creating "errors".

Posted: Wed Jan 14, 2004 4:20 am
by twigletmac
By using:

Code: Select all

<?include "header.htm"; ?>
you are relying on short tags (<? ?>) being enabled on the server (they are often disabled). To make your code more portable use:

Code: Select all

<?php include 'header.htm'; ?>
as long tags (<?php ?>) are always enabled.

Mac

Posted: Wed Jan 14, 2004 10:19 am
by bKeppel
Thanks!

I'll use that format for the future...