views:

62

answers:

3

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

+2  A: 

Did you try this in the first place?

<div id="section"><?php include ('path-to-your-file') ?></div>
Sarfraz
Awesome, thanks, i'll give it a try!
Milo
Why use JS if you can do it all in PHP?
nico
@nico: I thought he didn't want to use include (i was wrong of course) but before seeing this comment, i added that to my answer :)
Sarfraz
Thanks to all, I was unaware of include, is will really help my productivity!
Milo
+1  A: 

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.

nico
+5  A: 

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

Thomas