Question reg. PHP include code, recommended formating?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bKeppel
Forum Newbie
Posts: 2
Joined: Wed Jan 14, 2004 12:41 am

Question reg. PHP include code, recommended formating?

Post 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".
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
bKeppel
Forum Newbie
Posts: 2
Joined: Wed Jan 14, 2004 12:41 am

Post by bKeppel »

Thanks!

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