简体   繁体   English

如何将包含简单PHP的文件批量转换为HTML?

[英]How can I batch convert files with simple PHP includes to HTML?

I have several old websites that use no php other than simple include lines like this: 我有几个旧网站,除了简单的包含行外,不使用php,例如:

<? include_once "includes/header.php"; ?>

Is there any way I can batch convert them over to HTML files so they contain the included content? 有什么办法可以将它们批量转换为HTML文件,以便它们包含所包含的内容?

I'm hoping to host them as static files. 我希望将它们托管为静态文件。

您可以尝试在命令行中打开主PHP文件(而不是HTTP请求)并输出到文件。

php main.php > main.html

如果您具有访问命令行的权限,并且计算机上已安装PHP,则可以使用以下命令自动处理HTML文件(无需复制/粘贴)。

$ php file.php > file.html

I pieced together the following which finds all the php files and converts them to html: 我拼凑了以下内容,以查找所有php文件并将其转换为html:

find . -iname "*.php" -print | while read filename; do php $filename > "${filename%.*}".html ; done

Breakdown: 分解:

This finds all the php files in the current directory & child directories: 这会在当前目录和子目录中找到所有php文件:

find . -iname "*.php" -print

This grabs the filename: 这将获取文件名:

| while read filename;

This uses PHP to convert the files found to html: 这使用PHP将找到的文件转换为html:

do php $filename > "${filename%.*}".html ; done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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