Setting up to use .txt files as includes

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
eCentric
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2003 11:20 am
Location: Denver
Contact:

Setting up to use .txt files as includes

Post by eCentric »

I have gone to the Apache web site and it does not help. I've changed my Options to "Options +Includes" as they instructed and it still doesn't work. Does anyone else know how to set up includes so that when you use "require" or "include" that you can include a .txt as file extension?

Code: Select all

<?php
require ('2004/includes/footer_2004.txt')
?>
THis doesn't work on my server. ( Apache 2.0.39 running PHP 4.2.2)

Any assistance would be greatly appreciated.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the apache's index settings do not affect on a local require().

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
require ('2004/includes/footer_2004.txt');
?>
does this print any error message? And if: which?
eCentric
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2003 11:20 am
Location: Denver
Contact:

Post by eCentric »

Nope...no errors.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Also remeber that any PHP code in your includes still needs to have <? ?> tags around it.... even though it is being called into PHP.

I normally rename my include files with a .inc extension... and they work fine.
eCentric
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2003 11:20 am
Location: Denver
Contact:

Post by eCentric »

Good idea but that didn't work either. :cry:
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

This is a strange one.

What's in the file you are trying to include?
eCentric
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2003 11:20 am
Location: Denver
Contact:

Post by eCentric »

It's just html but I don't want to have to change it on all the pages....just in one place.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

The only thing left that it might be then is that there's something wrong with the HTML. If you use require() PHP will spit out any errors so we know it's not a PHP problem.

Double check where you're including the file... as you probably know the require() needs to be put where you want the contents on the .txt file placed in the page.

Also make sure you haven't done something silly (like we all do now and again) such as missing out any opening or closing tags ( such as <tr><td></td></tr> ).

Don't do this for example....

Code: Select all

<table>
<tr>
<? require("thefile.txt") ?>
<td>
</td>
</tr>
</table>
You'll just have to make sure everything is where it's supposed to be.
Post Reply