问题
I'm trying to get the Html source code from a php file and put it into an Html file using this:
file_put_contents('result.html', file_get_contents('index.php'));
After running this function, The "result.html" will contain the same PHP codes in the original "index.php" file, While I need "result.html" file to get the Html code after index.php has executed. Any Help Please?. Thanks.
回答1:
Another way (doesn't need an http server nor access to shell):
<?php
ob_start();
include('index.php');
$page = ob_get_contents();
ob_end_clean();
file_put_contents('result.html', $page);
?>
回答2:
You are simply copying php code into html file.
to get html source code you need to interpret php file
one way of doing this is:
file_put_contents('result.html', file_get_contents('http://localhost/path/to/index.php'));
回答3:
Use this code
file_put_contents('result.html', file_get_contents('http://localhost/yourproject/index.php'));
回答4:
You can try:
file_put_contents('result.html', shell_exec('php path/to/index.php'));
来源:https://stackoverflow.com/questions/22215465/php-file-put-contents-save-from-php-file