php include and html??

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
josh22x
Forum Commoner
Posts: 38
Joined: Tue Feb 26, 2008 11:17 am

php include and html??

Post by josh22x »

I am trying to use the php include statement in some html content. I am sorta confused about it.

When using the include statement, does the included file need to be a php file or can it be an html file?

Also where do I include the include statement in the html document? In the header?

Thanks
Josh
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php include and html??

Post by Christopher »

You can include either PHP or HTML files (or any other kind). But only the code between the <?php and ?> will be executed by PHP. So if the file has not PHP then nothing is executed and the contents are sent to the browser.
(#10850)
josh22x
Forum Commoner
Posts: 38
Joined: Tue Feb 26, 2008 11:17 am

Re: php include and html??

Post by josh22x »

So the content in my included file is just some hyperlinks that are contained in the menu section of my page like:

<li><a href="http://www.blabla.com">text</a></li>
<li><a href="http://www.blabla.com">text</a></li>
<li><a href="http://www.blabla.com">text</a></li>
<li><a href="http://www.blabla.com">text</a></li>
<li><a href="http://www.blabla.com">text</a></li>

That is all that is in the lincluded html file, no other tags, but it is not working. What am I doing wrong?

Thanks
Josh
bertfour
Forum Commoner
Posts: 45
Joined: Fri Mar 07, 2008 7:33 am

Re: php include and html??

Post by bertfour »

If the links above are in "links.html" you should have:

Code: Select all

<?
 
include('links.html');
 
?>
 
Somewhere in your php file.....
josh22x
Forum Commoner
Posts: 38
Joined: Tue Feb 26, 2008 11:17 am

Re: php include and html??

Post by josh22x »

I think I might have figured it out:

The file with the include tag within it has be be something.php, not something.html in order for it to work.

Is that a correct assumption?

Thanks!
Josh
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php include and html??

Post by Christopher »

Yes. But understand that is a web server setting. Usually web servers are configured to parse files with the extension .php as PHP scripts, but you could also configure your webserver to have .html or .xyz files parsed by PHP as well.
(#10850)
Post Reply