Help With Code

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
blair_24986
Forum Newbie
Posts: 2
Joined: Wed Oct 29, 2008 5:09 pm

Help With Code

Post by blair_24986 »

:banghead:
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;
 
 
 
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Help With Code

Post 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.
blair_24986
Forum Newbie
Posts: 2
Joined: Wed Oct 29, 2008 5:09 pm

Re: Help With Code

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Help With Code

Post 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
Post Reply