Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate a static html file from the output of a php script, using php

Tags:

file

php

static

get

I would like to generate a static html page from a php file and save it from an other php script. That script runs a bunch of echo functions, which when viewed in a browser is a nice html page. But when I run file_get_contents it opens that file as a file on the filesystem, not as a file in an url.

Do I need to call file_get_contents in a localhost/site/categories.php way? How can I get this path? This is the wrong code:

<?php
$file = file_get_contents("categories.php");
file_put_contents("categories.html", $file);
?>
like image 481
hyperknot Avatar asked Apr 15 '11 23:04

hyperknot


1 Answers

To get the finished output, you need to use the PHP url wrappers functionality and request it over the webserver. Then it's as easy as:

copy("http://localhost/site/categories.php", "categories.html");
like image 154
mario Avatar answered Sep 21 '22 23:09

mario