Author Topic: Converting html to php?  (Read 2354 times)

0 Members and 1 Guest are viewing this topic.

Offline WeatherBeacon

  • Chief
  • Forecaster
  • *****
  • Posts: 1369
    • http://www.wxbeacon.com
Converting html to php?
« on: September 13, 2008, 05:14:18 PM »

Hi all!

Forgive me if this is a naive question.

I would like to use more of the php scripts that are available to us through the kindness of several members. I understand that those run only when called from within a php file. Presently I have two php pages but the rest of my pages are shtml. (I switched from html to shtml so I could include common headers and footers.) Some of my pages also include javascripts, ajax, and css. (Bear in mind that the only language of this set that I "know" is html.)

To make a php page out of an (s)html page, is it merely a matter of using the php extension rather than shtml? I find it doubtful that it's that simple. To test it, I just copied my index.html page and called the copy index.php, and it seemed to load normally; I saw no difference. When I tried that with one of my shtml pages, I quickly realized that I had to use php's <?php include("filename.ext"); ?> command instead of shtml's <!--#include virtual="filename.ext" --> command, and then the php page appeared identicial to the shtml page (formatting intact and all).

Is it really that simple? Does one have to use different statements in the <head> section for a php file? Are there any other differences I need to know about?

Does php recognize all html commands?

(Note: I'm not asking about learning php commands. I'm just wanting to know what I need to do to my current (s)html pages so I can include php scripts.)

Thanks! :grin:

Kevin...
Mae govannen!
Kevin  (Member AMS) http://www.wxbeacon.com               Genesee County, Michigan
Hardware:  Davis Vantage Pro Wireless, Midland WR-300
Software: VWS 14.01p43, WeatherFlash, & GRLevel3

Offline SLOweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 3456
    • Weatherelement Moline IL
Re: Converting html to php?
« Reply #1 on: September 13, 2008, 05:34:04 PM »
Is it really that simple? Does one have to use different statements in the <head> section for a php file? Are there any other differences I need to know about?

Yes it's really that simple, no, you don't use any different statements, and no, there aren't any other differences... :)

Quote
Does php recognize all html commands?

Here's where you are kinda missing it. PHP is a language that runs on the server. All of the commands are interpreted and executed there. If the php script says to do so, the PHP "engine" returns stuff to the web server that is in html, which is then sent to the users computer. Their web browser then interprets the html to decide how to lay out the page to be viewed. PHP is never sent to the user, while HTML is.

For instance, Anole's Weather Graphics script is several pages of PHP, and requires an additional text file of data, but all it returns to the user is a image, and that's all they see, even if they try to view the source code.

I made that little distinction there about "If the php script says to do so..." because it's entirely possible to write PHP that can be called by a browser, but doesn't return anything back. I have some that do that to calculate some daily weather indexes and then write a data file back to the server. While I used a web browser to test the script, in normal use it's called by Linux's cron scheduler just after midnight.

As you have figured out, you can rename an HTML file to .php and it still works. The .php is needed to tell the server what to do with the file when someone calls it.

Chris
« Last Edit: September 13, 2008, 05:36:06 PM by SLOweather »

Offline WeatherBeacon

  • Chief
  • Forecaster
  • *****
  • Posts: 1369
    • http://www.wxbeacon.com
Re: Converting html to php?
« Reply #2 on: September 13, 2008, 05:41:30 PM »

Ah ... I gotcha. Thanks, Chris!

Regards,

Kevin...
Mae govannen!
Kevin  (Member AMS) http://www.wxbeacon.com               Genesee County, Michigan
Hardware:  Davis Vantage Pro Wireless, Midland WR-300
Software: VWS 14.01p43, WeatherFlash, & GRLevel3

Offline Carson Weather

  • Contributor
  • ***
  • Posts: 108
    • http://www.carsonweather.com
Re: Converting html to php?
« Reply #3 on: September 14, 2008, 02:09:24 AM »
You can also use php in an .htm(l) file with a slight modification to your .htaccess file.
Add this as the first line (assuming php5):

Code: [Select]
AddHandler application/x-httpd-php5 .html .htm
I use this on my site(s) and ALL of my files have .htm extensions.


Offline WeatherBeacon

  • Chief
  • Forecaster
  • *****
  • Posts: 1369
    • http://www.wxbeacon.com
Re: Converting html to php?
« Reply #4 on: September 14, 2008, 03:24:59 PM »

You can also use php in an .htm(l) file with a slight modification to your .htaccess file.
Add this as the first line (assuming php5):

Code: [Select]
AddHandler application/x-httpd-php5 .html .htm
I use this on my site(s) and ALL of my files have .htm extensions.

Ooo! Thank you! That may be my best bet. Thanks!

Regards,

Kevin...
Mae govannen!
Kevin  (Member AMS) http://www.wxbeacon.com               Genesee County, Michigan
Hardware:  Davis Vantage Pro Wireless, Midland WR-300
Software: VWS 14.01p43, WeatherFlash, & GRLevel3

Offline MesquiteWx

  • Forecaster
  • *****
  • Posts: 610
    • Mesquite Weather
Re: Converting html to php?
« Reply #5 on: September 14, 2008, 11:00:06 PM »
Make sure your server is running php5 though. This doesn't work with php4 or lower.

Offline Carson Weather

  • Contributor
  • ***
  • Posts: 108
    • http://www.carsonweather.com
Re: Converting html to php?
« Reply #6 on: September 15, 2008, 03:20:27 AM »

AddHandler application/x-httpd-php .php .htm .html

is what I used on my php4 sites (till they were upgraded  to php5) \:D/

Offline WeatherBeacon

  • Chief
  • Forecaster
  • *****
  • Posts: 1369
    • http://www.wxbeacon.com
Re: Converting html to php?
« Reply #7 on: September 16, 2008, 07:06:05 PM »

Thanks a lot, Carson! I'll give it a try.

Regards,

Kevin...
Mae govannen!
Kevin  (Member AMS) http://www.wxbeacon.com               Genesee County, Michigan
Hardware:  Davis Vantage Pro Wireless, Midland WR-300
Software: VWS 14.01p43, WeatherFlash, & GRLevel3