View Full Version : PHP parsing .htm files
07-12-2004, 06:14 AM
Hi, could anyone tell me how I set up my PHP to parse files with .htm and .html extensions. I know its not very good to do so but I need it for a special job and I cant do it on my server. Ive read the manual but still ??
Maybe its an easy change in PHP.ini that Ive missed? (as usual)
07-13-2004, 09:35 PM
If what you are asking is how to use PHP from within a file with an extension of .htm or .html, there are at least three ways.
If you only need limited php capabilities--that is, you don't need to pass the php script any data from the web page--you can build the php script externally and use SSI to Include it just like normal SSI includes. That is handy for more or less "standalone" php functions, like fetching and reporting some external datum or data.
Another thing you can do is to use mod_rewrite to transparently redirect calls to thispage.html on to thispage.php.
And a more direct answer from the PHPFAQ:
Using Apache can I get php to parse files not ending in .php?
Yes it is possible, to make it work on all sites on your webserver; change the following in your httpd.conf:
AddType application/x-httpd-php .php
to the following:
AddType application/x-httpd-php .php .htm .html
It is also possible to put this directive in the VirtualHost sections to do it per virtualhost basis. If that proves to be too much you can use .htaccess files to solve the task.
But, when you do it that way, the PHP processor will parse all files ending in .htm and .html, not just files ending in .php; that is, as you seem to be aware, a major performance hit.
07-13-2004, 10:18 PM
Thank you for your answer. I did not explain myself fully in my first post. I am on an IIS 6 server... So the .htaccess thing doesnt work on that one.
The statement I use mostly from php is the "include once". I am working on some files on a large site hosted on an Apache but since my testserver is IIS I havent figured out how I can run the stuff locally.
I have noticed that apache seems to have more functionality at the system level as a webserver. Since I also work with .NET applications I use IIS.
Maybe the best thing is to also install Linux and Apache. Or an Apache on Windows and turn of IIS.
If on IIS (i'm using 6.0) try doing the following:
Goto IIS Manager.
- Right click default site (or whatever you use).
- Home Directory Tab
- Add new, identical to your .php extension, but make sure to use the .html or .htm extension.
Restart, .html should now be parsed as PHP.
Also note you can use Apache in conjunction with IIS, just make it listen on a different port to 80.
07-14-2004, 03:59 AM
Thanks very much! I will try that at once. If you read this, since you seems to be an xml pro, I need to setup a small database on one of my sites and I thought I maybe could use XML (smaller, faster) the going through mySQL, is it hard to learn and setup? Where should I start. I have a basic knowledge of XML and I am a medium skilled php/C.. programmer?
You could use XML, the benefits are that you would have would be increased control of the data, and its extensible.
Using XML however would NOT be faster than using MySQL. From my use of PHP and XML I can definetly tell you its pretty damn sloooooooooooow.
But it really depends on the size of you XML files tho. What size will you be working with?
07-15-2004, 07:35 AM
Actually it would be a databse that kept track of files to be downloaded by users. I would give the database an index and get back a record with filedata (name, filename, size etc.) wouldnt be more then 50 to start and max 1000.
Oh, it'll be perfectly suited then.
You should install PHP 5.0 and play around with the new libxml XML DOM features, its MUCH improved, and a hell of a lot faster.
07-15-2004, 11:35 AM
That sounds good. I can do that on the server at home, but I dont think any of my service provider hase any version higher then 4.3.(7). I will check that anyway. I tried to access your xml tutorial but the link wouldnt open the page, maybe its on my side?
Can you recommend some more reading online about creating xml databases?
Theres no real tutorials for simple XML databases in PHP, theres a few for XQuery, but thats major overkill for your scenario.
I'd suggest reading and understanding the XML functions in PHP in the PHP manual. Also come up with your own XML structure. I'd recommend using as few attributes as possible to increase performance.
vBulletin v3.0.3, Copyright ©2000-2013, Jelsoft Enterprises Ltd.