Page 1 of 1
Help With Code
Posted: Thu Oct 30, 2008 3:30 pm
by blair_24986
I'm trying to get this perfect for my web page but i'm stuck in a repetitive circle. The problem is it displays a "1" on the index.php page after the included home.php .. I tried not putting the else include into a var and it fixed it but why is it doing it when its like this.
Code: Select all
if(isset($_GET['page'])){
$page = $_GET['page'];
$contents = include('page_includes/page'.$page.'.php');
}
else if(isset($_GET['image'])){
$image = $_GET['image'];
$image_contents = '<img src="images/gif_images/'.$image.'.gif">';
}
else {
$home = include('page_includes/home.php');
}
echo $contents;
echo $image_contents;
echo $home;
Re: Help With Code
Posted: Thu Oct 30, 2008 3:33 pm
by onion2k
include() is basically the same as pasting the contents of the file into the script at that point. When you do "$contents = include('page_includes/page'.$page.'.php');" it's the include() call that's 'echo'ing the contents of the file. $contents is actually set to the return value of include() ... 1 if it worked, 0 if it didn't. So you're printing the contents of the file followed by the return value. Consequently you get a 1 at the end.
Re: Help With Code
Posted: Thu Oct 30, 2008 3:57 pm
by blair_24986
Thank you .. i just do a straight include instead of putting it into a variable, if I really had the need to do so is there another method for accomplishing this without the return value being printed.
Re: Help With Code
Posted: Fri Oct 31, 2008 3:28 pm
by califdon
blair_24986 wrote:Thank you .. i just do a straight include instead of putting it into a variable, if I really had the need to do so is there another method for accomplishing this without the return value being printed.
http://us2.php.net/function.file-get-contents