General Community > Scripting Help

PHP include Statements?

(1/2) > >>

ApplianceJunk:
I'm trying to learn from example: 2 on this page.
http://w3schools.com/php/php_includes.asp

I create a index.html page with this code.


--- Code: ---<html>
<body>

<div class="leftmenu">
<?php include 'menu.php'; ?>
</div>

<h1>Welcome to my home page.</h1>
<p>Some text.</p>

</body>
</html>

--- End code ---

Then I create a menu.php page with this code as shown in the example.


--- Code: ---<a href="/default.php">Home</a>
<a href="/tutorials.php">Tutorials</a>
<a href="/references.php">References</a>
<a href="/examples.php">Examples</a>
<a href="/about.php">About Us</a>
<a href="/contact.php">Contact Us</a>

--- End code ---

The index page shows with the text from the .html page, but the menu.php does not seem to get added.

From what I think I know about php it seems the code in the example for the menu.php is not right.
I have tried adding the <?php tag and ?> at the end and other things such as echo and ; but I just can't seem to get the menu to show up when I view the index.html page.

Hope that make sense.

What I'm I doing wrong?

Thanks,

SMFHacks.com Team:
rename index.html to index.php

Only .php files can execute php code by default.

ApplianceJunk:
That works!
Seems so logical once I know, lol

So back to the menu.php I guess not all .php pages have to start with <?php and end with ?> then?

Hope it's ok for me to ask questions about examples given on another website.
I see w3shoools has a forum too, but SMF just feels like home. :)

Thanks!

SMFHacks.com Team:
They don't have to. You can use <?php ?> anywhere inside the file.
SMF uses one just at the start and bottom of the page then echo's all the output.

ApplianceJunk:
Thanks,

Navigation

[0] Message Index

[#] Next page

Go to full version