quick question about using require

Associate
Joined
30 Nov 2003
Posts
1,614
So i thought to make things easier I would use an includes file for my navigation to save changing of so many files.

Anyway I have done this and at first I couldnt figure out why it wasn't working. I thought it should work fine the way it was then I tried echoing out everything on each line of the file I was trying to include which works.

Why is it if your requiring it you have to echo out every line? It seems a bit of a chore, I thought it would see I wanted to include it and just plonk the contents in the page.
 
Yeah I'm using PHP. I thought I had had it working without echoing in the past and all examples I have seen don't echo either.

When I didn't echo it said there was an unexpected < in the included file which was my first div tag as when I removed everything from the file except the div tags it still did it. Soon as I echo'd the lines out it worked fine. :confused:

This is part of my index.php page
PHP:
<?php
 require ("include/navigation.php");
?>

This is the included file which didn't work.

PHP:
<?php
	<div id="nav">
	<a href="index.php">Home</a> <a href="sites.php">Sites</a> <a href="images.php">Images</a> <a href="resume.php">Resume</a> <a href="contact.php">Contact</a> <a href="aboutme.php"> About Me</a> <a href="blog.php">Blog</a> <a href="links.php">Links</a><br />
	</div>
?>

and here it is with the echo that makes it work

PHP:
<?php
	echo '<div id="nav">';
	echo '<a href="index.php">Home</a> <a href="sites.php">Sites</a> <a href="images.php">Images</a> <a href="resume.php">Resume</a> <a href="contact.php">Contact</a> <a href="aboutme.php"> About Me</a> <a href="blog.php">Blog</a> <a href="links.php">Links</a><br />';
	echo '</div>';
?>
 
Last edited:
Zaphan58 said:
This is the included file which didn't work.

PHP:
<?php
	<div id="nav">
	<a href="index.php">Home</a> <a href="sites.php">Sites</a> <a href="images.php">Images</a> <a href="resume.php">Resume</a> <a href="contact.php">Contact</a> <a href="aboutme.php"> About Me</a> <a href="blog.php">Blog</a> <a href="links.php">Links</a><br />
	</div>
?>

well of course that won't work. that isn't php code. just lose the php tags. :)
 
Back
Top Bottom