/    Sign up×
Community /Pin to ProfileBookmark

Please clarify include() in php or HTML

Hi guys,

I have searched the forums, and I think I understand now but I would appreciate some clarification.

I’m just learning php and I thought as my first exercise I would create a header file with the doctype info etc. to include at the top of all my pages.

Is this correct:

[QUOTE]

The outer/calling page needs the “.php” extension.

[/QUOTE]

and

[QUOTE]

The script/file being included/called can have either a php or html or even “*.inc” extension.

[/QUOTE]


That being the case, I would have to change all my html pages to php.
If so, can I just change the html file extension to “*
.php” without having to do anything else special apart from adding the include() function at the top of my pages?

Also, does that mean it makes no difference to the function of the page weather it has either extention? I’m still trying to get my head around using php within html pages, and html within php pages/scripts – It all seems the same – sort of. ?

I did try it and it seems to work fine but I would like to make sure lest something goes wrong down the track.

If someone could sum it up in a way that makes sense and easily remembered that would be good.

Thanks.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@JKnochJan 04.2008 — The outer/calling page needs the ".php" extension.[/QUOTE]

Thats correct.

Heres an example of how the main or root page might look
[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Stevesite</title>
<link href="site.css" rel="stylesheet" type="text/css" />
</head>

<body bgcolor="#6e6e6e">
<table cellpadding="0" cellspacing="0" width="800" align="center">
<tr>
<td><?php include("tiles/commonheader.php"); ?></td>
</tr>
<tr>
<td><?php include("tiles/bodycontent.php"); ?></td>
</tr>
<tr>
<td><?php include("tiles/commonfooter.php"); ?></td>
</tr>
</table>

</body>
</html>[/CODE]

I happen to put all my included pages in a "tiles" folder so they are not confused.

The page being called can have any usable extension but they do not have any header or body information because you are just including the information in the main page.


It could look like this
[CODE]<table cellpadding="0" cellspacing="0">
<td width="51px">
<img src="tiles/images/leftbumper.jpg" width="51" height="387">
</td>
<td width="729px">
<?php include("tiles/contentshome.php"); ?>
</td>
<td width="20px">
<img src="tiles/images/rightbumper.jpg" width="20" height="387">
</td>
</table> [/CODE]


As shown you can have an include in the included page, and you can have multiple includes on a page.

The easiest way to think of it is that when all the included pages are put together then form 1 page, so if you have many body, head, ect tags, the page will error out.
Copy linkTweet thisAlerts:
@Stevo22authorJan 04.2008 — Thanks a lot JKnoch,

That clears things up - I have a book on php and I'm sure it discusses it somewhere, but I couldn't find it easily.

I beleive it's always [I]quicker [/I]to learn from someone else than a book! ?

much appreciated.
Copy linkTweet thisAlerts:
@JKnochJan 04.2008 — No problem, I've ask so many questions on forums, that its nice to actually answer a question once in awhile.
×

Success!

Help @Stevo22 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...