I need to embed the contents of a text file in an .htm page. I can't change the ending to PHP. The method I'm trying to use is:

require("/PathToTextFile");

This works fine if I change the ending to .php but I need the embedded code to run in the middle of the .htm page.

I've tried to use the <SCRIPT language='php' method, no cigar.

Thanks,

Stan

    I've tried that. Just copied this out of the page.

    <?PHP
    require("/home/lhost/public_html/cgi-bin/newspro/news.txt");
    ?>

    I works fine if I change the page name to a .php ending so I know the path is correct. The page displays without errors.

    Thanks,

    Stan

      Your Webserver controls which extensions are to be parsed by what language.

      Therefore, you need edit httpd.conf (if you have access) or put a .htaccess file in your root directory with the following line.

      AddType application/x-httpd-php .php3 .phtml .php .php4 .html .htm

      Extensions that can be parsed by PHP are seperated by a space. You will find somehting similiar in httpd.conf if you have access.

        Bingo!!

        I'd deleted the .htaccess file yesterday, it was still in the trash can.

        Doing the impossible isn't hard, overcoming stupidity is a life long quest.

        Thanks,

        Stan

          Dumb question here by an eavesdropper 🙂

          Bretticus- if my website is hosted by someone other than me, is it possible for me to modify an .htaccess file such as you directed and put it in my own root directory? Will that override the webserver's .htaccess? I don't believe they have the system set up to parse PHP through .htm or .html files... and if I could have that capability, well gee that would be quite peachy keen because of some website structure issues we have going on.

          Just curious-

          -Elizabeth

            Actually, one of the purposes of .htaccess (maybe the sole purpose) is to be able to set additional server directives. The Apache Web server doesn't have an .htaccess, it has an httpd.conf file. Setting these directives in httpd.conf is more efficient as you reload apache and the configuration works, as opposed to .htaccess where it has to be read with every page load under the directory where the .htaccess file resides. Therefore, if you don't have access to the httpd.conf file, like most people who have a site with a hosting company, you can set dicrectives in .htaccess that will only affect your site.

              Bretticus,
              Thanks for the tip! But when I altered the .htaccess file with the line you provided earlier, it caused the pages in my site (php and html both) to try and download themselves to an individual's temporary files and in a new browser window... instead of just parsing the code and providing the results in the open window.

              Why do you think this would happen?

              -Elizabeth

                It's possible that PHP is not installed on their Web server or that the PHP mod is not being called in their main configuration file (httpd.conf)

                Alternatively, they may have AllowOverride none set for your directory or all directories.

                Talk with your hosting providers.

                  Thanks Bretticus- I will do that! 🙂

                  -Elizabeth

                    Just a quick note to add to these:
                    It isnt really a good idea to add .htm and .html to the list of php extensions as this causes ALL pages with these extensions to be parsed by the php engine. This will slow down the download of all html files unnecessarily and therefore your site :-)

                    If this is ok, then go right ahead, but I just thought i would mention it.

                      Write a Reply...