jmasterx
jmasterx

Reputation: 54113

Include a repetitive chunk of HTML

I basically have a div on my site that always has the same stuff. However, this div is not present on all pages which is why I won't use the dynamic web template. I was wondering if it was possible for PHP to get the code from a document on the server and put in into the div?

Ex:

<div id="section...

then my text file contains

<p>hello</p>

Basically I want PHP to put it into the div when the user sees it.

If theres a smarter way of acheiving this I'd be open to it as well.

Thanks

Upvotes: 3

Views: 429

Answers (3)

Sarfraz
Sarfraz

Reputation: 382696

Did you try this in the first place?

<div id="section"><?php include ('path-to-your-file') ?></div>

Upvotes: 2

Thomas
Thomas

Reputation: 181745

Simply include() the file. The interpreter will drop out of PHP mode back into HTML mode, outputting anything it encounters.

Upvotes: 5

nico
nico

Reputation: 51640

Just have a file with some echo statements that generate your div and then include it only when required.

How to control whether to include it or not depends on how your website is built.

For instance if you have DB entries for your pages add a column called includediv (you can probably come out with a better name...) and if that is true you include the file otherwise not.

Upvotes: 1

Related Questions