Page 1 of 1

Using PHP to assemble and write to html files

Posted: Wed Apr 27, 2005 8:50 pm
by hermione
Hi, all. I'm totally new to PHP, so please forgive me if my questions seem basic.

I am considering downloading PHP, but am unsure of whether I can do the following:
  • Install PHP to my WinXPPro system, without having to install Apache/ISS, a web server, or a database. I just want to use PHP to assemble pages, as below.
  • Create boilerplate and unique content elements, that PHP can use to build pages.
  • As a final step to assembly of a page, have PHP strip out href links which link back to the page being assembled, so that the user can look at the navigation and see that the unlinked text refers to the current page.
  • Have PHP write these pages to .html files, so I can upload them as static HTML pages. They will be static pages, and no server-side page generation would be necessary. I would, thus, be able to use PHP to assemble pages that won't necessarily go onto a PHP-compatible server.
So, is this even possible? Thanks, in advance, for any help.

Posted: Wed Apr 27, 2005 9:58 pm
by jmrdeuce32
You would need some sort of server to run the PHP. Apache on your local machine or you could do it through a web server. You would then have to create a form or delimited text file or something to pass the data to the PHP. Then use something like the following to create the file with the content you have produced.

Code: Select all

<?php 
$filename = 'C:\folder\newPage.html';//must be absolute path I think
$content = '<html><head><title>New Page</title></head><body>Content...</body></html>';
$file = fopen($filename,'x'); //'x': create and open for writing only
fwrite($file, $content);
fclose($file);
?>
Open function: http://us3.php.net/manual/en/function.fopen.php
Write function: http://us3.php.net/manual/en/function.fwrite.php

Posted: Thu Apr 28, 2005 1:53 am
by n00b Saibot
you can run php from the command line too... :arrow: http://www.php.net/features.commandline