Dan G Nelson
Dan G Nelson

Reputation: 932

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:

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

Is there any way I can batch convert them over to HTML files so they contain the included content?

I'm hoping to host them as static files.

Upvotes: 0

Views: 266

Answers (3)

Dan G Nelson
Dan G Nelson

Reputation: 932

I pieced together the following which finds all the php files and converts them to 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:

find . -iname "*.php" -print

This grabs the filename:

| while read filename;

This uses PHP to convert the files found to html:

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

Upvotes: 1

user8711291
user8711291

Reputation:

If you have access to command line and PHP is installed on your machine you can use the following command the HTML files automatically (without copy/pasting).

$ php file.php > file.html

Upvotes: 0

Gras Double
Gras Double

Reputation: 16373

You could try opening the main PHP file in command line (instead of HTTP request) and outputing to a file.

php main.php > main.html

Upvotes: 1

Related Questions