WXforum.net

Web Weather => Weather Website PHP/AJAX scripting => Topic started by: anchorageweather on January 14, 2008, 08:55:58 PM

Title: Is there any way to change a .php file to a .html in the local template folder?
Post by: anchorageweather on January 14, 2008, 08:55:58 PM
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.
Title: Re: Is there any way to change a .php file to a .html in the local template fold
Post by: saratogaWX on January 16, 2008, 11:12:15 PM
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.   ](*,)
Title: Re: Is there any way to change a .php file to a .html in the local template fold
Post by: SLOweather on January 16, 2008, 11:42:18 PM
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. 
Title: Re: Is there any way to change a .php file to a .html in the local template fold
Post by: ncherry on January 27, 2008, 01:44:58 PM
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.
Title: Re: Is there any way to change a .php file to a .html in the local template fold
Post by: anchorageweather on January 27, 2008, 03:04:27 PM
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?
Title: Re: Is there any way to change a .php file to a .html in the local template fold
Post by: ncherry on January 28, 2008, 02:36:08 PM
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?
Title: Re: Is there any way to change a .php file to a .html in the local template fold
Post by: anchorageweather on January 28, 2008, 04:32:18 PM
I'll give it a shot and see if it works!!!!