简体   繁体   中英

Converting a .php file to a .html file?

I have a .php file which has several queries in it. I want the output file as a .html file...

Is there any way to do this. I am currently doing this by saving, using my browser, that executed PHP file, as an .html file. But when I launch my product that should not be the case of the client.

Please suggest a way, thanks in advance...

Here is a sample code:

<?php

ob_start();

// your PHP / HTML code here

file_put_contents('where/to/save/generated.html', ob_get_clean());

?>

Another option is to use apache's mod_rewrite or the IIS equivelant to rewrite your URL's from the browser perspective.

This would require no coding change, make sure the Apache extension is installed and add this to the .htaccess file of your root web directory:

RewriteEngine on
RewriteBase /
RewriteRule ^([^/]*)\.html$ $1.php?%{QUERY_STRING} [NC]

Not sure if I understand the question right.
But you can generate html files from php over command line:

php index.php > index.html

您可以使用输出缓冲( ob_start等),然后将缓冲区的内容写入脚本末尾的文件

Is this ( this ) what you need?

If these are not options, you can always curl to the page if it's running on a web server/

It looks like you want to save a static version of a dynamic web site. A tool like WinHTTrack comes in handy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM