dominovision Posted February 8, 2009 Share Posted February 8, 2009 Hi All, Fairly new to php but not programming... I want to load some php files into variables in the main page.. the files are pulled in ok, however when echoing them out a '1' appears after each line. I think it might be returning a true as well? there are no '1''s in the included files. I want to load them into variables as will move to db driven pages afterwards. Any ideas? See it in action at: www.royaldocks.net/bb/home.php <?php $headername = "component/header.php"; $footername = "component/footer.php"; /* Load all the files we need into variables then echo them out*/ if(file_exists($headername)){ /* go get it */ $header = require($headername); }else{ $header = "No Header"; } if(file_exists($footername)){ /* go get it */ $footer = require($footername); }else{ $footer = "No Footer"; } ?> <html> <head> </head> <body> <?php echo $header . "<br />"; echo "where are the nos coming from ?" . "<br />"; echo $footer . "<br />"; ?> </body> </html> Thanks Alastair Quote Link to comment https://forums.phpfreaks.com/topic/144330-solved-includes-and-loading-pages-into-variables-1s-appearing/ Share on other sites More sharing options...
bobbinsbro Posted February 8, 2009 Share Posted February 8, 2009 require/include return true/false for success/failure. to get the contents of a file into a variable use file_get_contents('filename); Quote Link to comment https://forums.phpfreaks.com/topic/144330-solved-includes-and-loading-pages-into-variables-1s-appearing/#findComment-757342 Share on other sites More sharing options...
dominovision Posted February 8, 2009 Author Share Posted February 8, 2009 The file_get_contents did the trick!.. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/144330-solved-includes-and-loading-pages-into-variables-1s-appearing/#findComment-757419 Share on other sites More sharing options...
.josh Posted February 8, 2009 Share Posted February 8, 2009 fyi file_get_contents loads the entire file into one string. If you're wanting to loop through the file line by line, file will take your file and explode at the line breaks and make an array. Quote Link to comment https://forums.phpfreaks.com/topic/144330-solved-includes-and-loading-pages-into-variables-1s-appearing/#findComment-757427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.