websiteguy Posted January 2, 2007 Share Posted January 2, 2007 Hi,Probably a simple question, but then I am a noobie. I added a couple of static html pages to a PHPBB2 forum site. I want to use a .txt file so the site admin, (no web or html knowledge), can occasionally modify and upload to the servor. The news.txt file looks like this:<h1>UBRS Raid December 17th</h1><br /> <br /> <br /><h2>Slaughtering The Beast!</h2><br /><img src="images/the-beast-opt.jpg" alt="The Beast" width="650" height="462" /><br /> <br /> <br /><h2>Drakki Down!</h2><br /><p><img src="images/General-Drakkisath-opt.jpg" alt="General Drakkisath" width="650" height="432" /></p><br /><p>Wicked completed their first successful UBRS run. Congrats to everyone<br />involved. Great teamwork, great fun, and greater things lay ahead!</p><br /> <br /> <br />I put an include file at the spot in the index.html page I wanted this to appear.<?php include(“news.txt”); ?>I get nothing at all. Can someone tell me what I'm missing? Thanks,Websiteguy Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/ Share on other sites More sharing options...
Psycho Posted January 2, 2007 Share Posted January 2, 2007 It may be attempting to parse the included file as PHP. Have you viewed the source of the output? Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151779 Share on other sites More sharing options...
Philip Posted January 2, 2007 Share Posted January 2, 2007 I could be wrong, but I think here's your problem:[quote]I put an include file at the spot in the index.html page I wanted this to appear.[/quote]Since you have some PHP in your code, you need to save it as index.php instead of index.html Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151788 Share on other sites More sharing options...
websiteguy Posted January 3, 2007 Author Share Posted January 3, 2007 That could be a problem. I already have a index.php file. That would be the forum home page. I added a index.html page as the sites home page so it would go to that first, then I have a button link on index.html to index.php (forum).I didn't understand mjdamato's question about veiwing the source of the output.Thanks,Websiteguy Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151794 Share on other sites More sharing options...
Philip Posted January 3, 2007 Share Posted January 3, 2007 Well, yeah that could be a problem. Just curious: why didn't you install it in a folder?You have some options:[list][*]rename index.php to something else and change all the links[*]move all the forum to a folder[*]have a meta refresh on index.html[/list] I cant think of anymore, too tired, sorry :P Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151796 Share on other sites More sharing options...
websiteguy Posted January 3, 2007 Author Share Posted January 3, 2007 None of the options sound too good, but then maybe I don't completely understand. (Learning everyday!) I installed this forum several months ago. Now the Home Page was requested. Moving the forum to a subfolder could be a nightmare. (Forum is installed at the root level of the domain). I first considered a redirect, but didn't know how to make it conditional when coming from the home page to the forum. (Lesson learned - Plan ahead!)I am currently learning PHP to write complete websites using PHP. Sounds like the ticket.Thanks,Websiteguy Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151811 Share on other sites More sharing options...
Philip Posted January 3, 2007 Share Posted January 3, 2007 No problem, I'll try to think of more suggestions ;) Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151813 Share on other sites More sharing options...
Psycho Posted January 3, 2007 Share Posted January 3, 2007 You could try just renaming the forum index page. There's a good possibility it may still work. Or you could talk to your host and have another page take precedence over "index" for your site - perhaps home.php. Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151823 Share on other sites More sharing options...
websiteguy Posted January 3, 2007 Author Share Posted January 3, 2007 I did think about creating a home.php and doing a redirect from there to the index.html home page. Or try naming it home.html, but I tried just uploading the index.html page first and it worked.Unless my Host can change the start page on just this domain, otherwise I have 5 domains on my account at the time. Appreciate the help,Websiteguy Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151829 Share on other sites More sharing options...
websiteguy Posted January 3, 2007 Author Share Posted January 3, 2007 So then, am I understanding this correctly? You can only use include statements in a .php file? There isn't any way to mix php into a .html page? Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151841 Share on other sites More sharing options...
corbin Posted January 3, 2007 Share Posted January 3, 2007 You could try to use .htaccess...Open notepad, hit file->save as.In the filename box type ".htaccess" (with the quotes!)Put[code]DirectoryIndex default.php index.php home.php index.html home.html[/code]In the .htaccess file and then upload it to your web server.Rename index.html to default.php and it will go to that page first, allowing you to keep index.php so you do not have to alter links, and it will make it go to default.php first (assuming your host allows you to do .htaccess). Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151846 Share on other sites More sharing options...
websiteguy Posted January 3, 2007 Author Share Posted January 3, 2007 Thanks!I'll look into that one. Certainly sounds like a possibility. Then I should be able to do an include into the default.php to solve the problem. Hats off to all the guys that help and to the PHP Freaks forum! Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-151901 Share on other sites More sharing options...
websiteguy Posted January 5, 2007 Author Share Posted January 5, 2007 I did a DirectoryIndex in the .htaccess file and changed my index.html to home.php. All that worked perfectly. Now I'm getting errors from my include. I'm sure all the errors are related to a path problem, but I've been reading and searching the net and am really stuck. Could someone point me in the right direction? Here are the errors:Warning: main(“newstxt”) [function.main]: failed to open stream: No such file or directory in /home/xcelwebw/public_html/thewickedguild/home.php on line 42Warning: main(“newstxt”) [function.main]: failed to open stream: No such file or directory in /home/xcelwebw/public_html/thewickedguild/home.php on line 42Warning: main() [function.include]: Failed opening '“newstxt”' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xcelwebw/public_html/thewickedguild/home.php on line 42This is my include:<?php include(“news.txt”); ?>It's located in /thewickedguild folder.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-153200 Share on other sites More sharing options...
rab Posted January 5, 2007 Share Posted January 5, 2007 [quote="php.net"]The include() statement includes and [b]evaluates[/b] the specified file.[/quote]Notice the evaluates. If you need to print the files contents then just use filesystem functions, IE fopen fread. Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-153204 Share on other sites More sharing options...
websiteguy Posted January 5, 2007 Author Share Posted January 5, 2007 Not sure I thoroughly understand, but as usual, I'll check it out on the net and the PHP book I've started. Just a noobie. I thought about using echo, but I saw other examples that worked with only the include statement.Thanks for the quick response. Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-153213 Share on other sites More sharing options...
websiteguy Posted January 6, 2007 Author Share Posted January 6, 2007 I finally solved the problem, and I got this from the PHP Freaks basics tutorials. I used the $docroot with the dirname() function and the _FILE_ constant to find the correct path.<?php $docroot = dirname(__FILE__).'/'; require_once($docroot.'news.txt'); ?> Thanks again to all the people on the forum that helped me and to the great tutorials on the PHP Freaks site!! Quote Link to comment https://forums.phpfreaks.com/topic/32626-solved-include-file-to-add-html-text/#findComment-154190 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.