Using PHP to assemble and write to html files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hermione
Forum Newbie
Posts: 1
Joined: Wed Apr 27, 2005 8:24 pm

Using PHP to assemble and write to html files

Post 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.
jmrdeuce32
Forum Newbie
Posts: 15
Joined: Wed Apr 27, 2005 5:45 pm
Location: Naples, FL

Post 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
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

you can run php from the command line too... :arrow: http://www.php.net/features.commandline
Post Reply