Author Topic: Is there any way to change a .php file to a .html in the local template folder?  (Read 3211 times)

0 Members and 1 Guest are viewing this topic.

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
I am in the process of trying to set up talbert1952's (Tom's) email service using Weatherlink:

http://tobaccovilleweather.com/WeatherlinkEmail.html

Instead of emailing a .html file, I'd like to use the info in a .php file (I'd like to include a short term forecast in the email and need .php to call the info).  Here is an example:

http://eetee.us/station/mailer.php

Here is my question;  it is possible to take a .php file, either on my computer or on my server, and convert the results to .html,and then store them on my computer - so Tom's software can send out the info in a daily email.  Hope that makes sense.  Thanks for any ideas.
South of the Tracks, Anchorage, KY

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6766
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
It does make sense (I think).

The issue is that a webserver with PHP installed has to run the PHP in the page to generate the HTML for you to use (and mail).  If you mail an un-executed PHP script to someone, they'll never see the HTML output at all.

So.. the .php has to be executed by a PHP interpreter.  You can do that on your own system by installing something like XAMPP (Apache/PHP/mySQL server-in-a-box), then use the command line PHP command to execute the PHP script, and pipe the output to a file with type .html, then mail that file.

Hope this helped more than confused :-)

Best regards,
Ken

BTW, YMMV if I didn't understand the question in the first place.   ](*,)
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline SLOweather

  • Administrator
  • Forecaster
  • *****
  • Posts: 3434
    • http://www.sloweather.com
I was thinking of running the PHP on the server in a cron job with wget, and then mapping the output folder with the file in it on the local machine as a drive letter with WebDrive. 

Offline ncherry

  • Member
  • *
  • Posts: 9
  • Author: Linux Smart Homes For Dummies
    • Linux Home Automation
Under Linux (and would venture a guess Windows too) you can run from the command line php filename.php >filename.html and that should work. I used this for a while with some customer scripts I pulled together (shell, Perl and PHP). I was just too lazy to rewrite them, especially when a few quick commands in php would work. :-)

In programming a lazy programmer can be a good programmer (if I do say so myself  \:D/ ).

I will admit that the wget is a good idea also.

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
Under Linux (and would venture a guess Windows too) you can run from the command line php filename.php >filename.html and that should work. I used this for a while with some customer scripts I pulled together (shell, Perl and PHP). I was just too lazy to rewrite them, especially when a few quick commands in php would work. :-)

In programming a lazy programmer can be a good programmer (if I do say so myself  \:D/ ).

I will admit that the wget is a good idea also.

At the risk of sounding stupid - can you explain this again.  Do I have to have access to the Apache server to do this?
South of the Tracks, Anchorage, KY

Offline ncherry

  • Member
  • *
  • Posts: 9
  • Author: Linux Smart Homes For Dummies
    • Linux Home Automation
Under Linux (and would venture a guess Windows too) you can run from the command line php filename.php >filename.html and that should work. I used this for a while with some customer scripts I pulled together (shell, Perl and PHP). I was just too lazy to rewrite them, especially when a few quick commands in php would work. :-)

In programming a lazy programmer can be a good programmer (if I do say so myself  \:D/ ).

I will admit that the wget is a good idea also.

At the risk of sounding stupid - can you explain this again.  Do I have to have access to the Apache server to do this?

Not stupid, this is so simple that it's not obvious. There is a module for PHP that works with Apache. If that's all you have installed then this won't work very well but there is also a separate package called php. Apache can still call it but his method runs slowed than the module. If you drop out to a command prompt and type php filename (where filename is any text file in the directory). If you have php then the file will be listed to the screen. If you don't have php then you'll get an error about not having php.

To convert a php file to the 'static' html you type this:

php filename.php >filename.html

Here's an example (I did this under Linux):

Code: [Select]
Linux$ cat helloworld.php
<?
echo "<?xml version=\"1.0\"?> <!--  encoding=\"utf-8\" -->\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Hello World</title>
</head>
<body>

<?
  // Simple embedded PHP code embedded inside the HTML code
  // This is probably not a great example but what the heck?
echo "<h1>Hello world!</h1>";
echo "<p>Hello world!</p>";
?>
</body>
</html>

Linux$ php helloworld.php
<?xml version="1.0"?> <!--  encoding="utf-8" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Hello World</title>
</head>
<body>

<h1>Hello world!</h1><p>Hello world!</p></body>
</html>
Sorry about the odd first few lines of the helloworld.php file. PHP doesn't like to see the "<?" used by the xml tag so I cheat.

In this example I did redirect the output of PHP to filename.html instead I just let it display to the screen. I did this so you would see the output. Had I redirected the output you could still see the output by cat'ing the filename.html file (or under Windows use type).

Does that help?

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
I'll give it a shot and see if it works!!!!
South of the Tracks, Anchorage, KY