PHP and HTML

Miscellaneous Forums/General Discussion/PHP and HTML

I'm no PHP guru and need a little help.

Let's say I have the same sidebar html code on every page of a website. I don't want to manually go to each page to do changes and would like to have a single php file(if there's another way let me know) containing this code. Now, how would I include a php file and then call the function in the html?

No, I don't want to name the page that contains the sidebar with a .php extension.

<!-- how do I include it?>
<body>
<div id="sidebar">
<!-- how do I make it draw?>
</div>
</body>


Note: bb code would be so much easier for my task. Include "sidebar.bb" : DrawSidebar() Too bad it's not possible.

Oh, easy. You can't without having the page as a .php.

You can include in html, but you can't include a php that runs into a standard html. As far as I know.

You can include a .php into another .php, however.


EDIT

so you can have index.php which draws from sidebar.php... in sidebar.php there is just a defined function that echos out what you need and does all the processing.

then you can call it in index.php anywhere you want.

EDIT 2

<?php
include 'sidebar.php';
?>

that would include it. you could also not have a function in sidebar.php and just include it where on the page you want it...

that is how www.omgwtflmao.com/index2.php 's includes work... each major section is just called straight in.. in the order I want them to float above eachother (as divs)

Thanks Dampe!

http://www.tizag.com/phpT/include.php
I found it and it helps a lot, now I just have to give it a try.

Now i have to convert all the html files to .php, now that sucks.

The file you include doesn't actually have to have the .php extension. Only files that actually have some php code in them need it. Though there is no reason not to just have .php on all files, in case you later want to throw some php code at them.

Check php.net for php documentation. It's actually quite simple to use php, and you can do some very cool things with it.

Ragnar

need things, like making this forum! haha