The Idea
lynx -source http://localhost/dynpages/index.php4 > C:DocumentsStaticPagesmywebsiteindex.html lynx -source http://localhost/dynpages/page2.php4 > C:DocumentsStaticPagesmywebsitepage2.html lynx -source http://localhost/dynpages/page3.php4 > C:DocumentsStaticPagesmywebsitepage3.html lynx -source http://localhost/dynpages/page4.php4 > C:DocumentsStaticPagesmywebsitepage4.html
<?php
define
('SLASH', ''); //* this is for use under Win9x;
//* under linux, use '/'.
define('
CRLF', chr(13).chr(10));
$httpbase="http://localhost/samplesite"; //* local URL for your pages
$dyndir="E:/xitami/webpages/samplesite"; //* (do not use backslashes)
//* where your webserver keeps your pages
$staticdir="C:/windows/desktop/samplewebsite/generatedpages/online";
//* where you want your pages to be put
$parameters="?outputas=online"; //* parameters you might need
function changeslashes($path) {
return str_replace("/", SLASH, $path); //* useful under Windows
};
function subdir($path) {
global $dyndir;
if ($dyndir!=$path) {
return substr($path, strlen($dyndir)-strlen($path));
}
else {
return '';
};
};
function destination($path) {
global $staticdir;
$dest=$staticdir . subdir($path);
$dest=changeslashes($dest); //* useful under Win
return $dest;
};
function searchdir($dirname) {
global $httpbase, $parameters;
$handle=opendir($dirname);
while ($file=readdir($handle)) {
if ($file !='
.' && $file !='..') {
if (is_dir($dirname.'/'.$file)) {
if (!is_dir(destination($dirname).'
/'.$file)) {
echo "mkdir " . destination($dirname). SLASH . "$file" . CRLF;
}
searchdir($dirname.'/'.$file);
} else {
if (substr($file, -5)==".php4") {
$newname=substr($file, 0, strlen($file)-5).'.html';
echo "lynx -source $httpbase" . subdir($dirname) .
"/$file$parameters > " . destination($dirname) . SLASH . "$newname" . CRLF;
} else {
echo "copy " . changeslashes($dirname) .
SLASH. "$file " . destination($dirname) . SLASH. "$file" . CRLF;
}
}
}
closedir($handle);
};
searchdir($dyndir);
?>
PHP -q generatepages.php4 > generatepages.bat generatepages.bat
- online
to use when you generate static pages to be published at an internet
site (links have to get .html extension, links to directories have no
file name added) - offline
to use when you generate static pages to be viewed off line, with no
webserver involved (links have to get .html extension, links to
directories have to be added index.html) - print
to use when you want to print the pages you are generating (I choose
a different stylesheet, and write remote URLS in brackets after linked
text)