What I'm trying to do is run a script that opens my PHP files and then saves them in HTML. This is what I'm using:
Code: Select all
<?php
$files = file("filelist.txt");
for($i = 0; $i < count($files); $i++) {
ob_start();
include($files[$i]);
$page = ob_get_contents();
ob_end_clean();
if(strpos($files[$i], ".php") > -1) {
$file = fopen(substr($files[$i], 0,strlen($files[$i])-4) . ".html",'w');
fputs($file, $page);
fclose($file);
}
}
?>The problem I'm having is with trimming the URLs in the text file (filelist.txt). Right now I'm just testing it with 2 URL strings like this:
Filelist.txt
/var/www/vhosts/mysite.com/httpdocs/firstpage.php
/var/www/vhosts/mysite.com/httpdocs/secondpage.php
After running the script, this is what I get:
firstpage..html
secondpage.html
The second page is fine, but obviously the first is not with the additional . (dot) before the extension. Now I'm pretty sure the issue has to do with the extra character after each line until the last one in the text file, which is somewhat of a mystery to me. I've tried playing around with the trim() function but to no avail. For example, I took line 5 from the script above:
include($files[$i]);
and replaced it with:
include (trim($files[$i]));
But that didn't solve my problem.
If anyone has an idea on what I'm doing wrong and how to fix it, I'd really appreciate it. If there's a simple way to amend the script with the trim function or if I can do something to the text file, either is fine. I am just hoping for a solution.
Thank you in advance!