2

This feels like an extremely n00b question, but here goes...

I have a series of HTML files with a small amount of HTML content inside each (exported from a live system). Its not feasible to change file extensions, as I will not be the person performing this 'export - burn to CD' process when I hand my project over.

Here's a sample page, its extremely basic, it is "01.html":

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/styles.css" />
<title>Introduction</title>
</head>
<body>
<h1 class="chaptertitle">Introduction</h1>
<div>
    <p>FBT is imposed on non-cash benefits provided to employees in addition to their normal cash salary. The main categories of fringe benefit for Administrator User are:</p>
    <ul>
        <li>The private use, or availability for private use, of an employer’s motor vehicles;</li>
    </ul>
</div>
</body>
</html>

The files are linked to from a main page, everything works fine in that regard - but I am sure I've seen pages with a .html extension parse PHP syntax, how can I enable/ do this? Currently, I'd thought I could do a search/replace on things like 'Administrator User' in the above example to something like:

<?php echo $CFG->username; ?>

...where that variable is defined and available - but the page is being parsed as HTML. In some ways this isn't a surprise, in some ways it is, as like I say I'm sure I've seen PHP code parsed in a file with a .html extension.

It is running on a Server2Go stack (for burning to CD), but during testing it is running on a WAMP stack. I'm not able to modify much about Server2Go.


Ack! Sorry, to clarify:

everythign inside the <body> tag is pulled out and used in a PHP context, a page named 'generate_book.php' which displays the pulled out contents as the PHP pages' own <body> tag.

Sorry, that was somewhat important :P

1
  • Meh, I worked around the problem by adding a config variable which is then used in a string replacement call to replace an export-generated string with one which someone can update in a config file, before burning to CD. I can get away with this because the string replacement is essentially the only PHP in these HTML files. I'll close this question after... leaving for anyone to check up on/read about quickly. Commented Apr 3, 2011 at 22:56

4 Answers 4

5

Well I'm rather sure you're not very accustomed to the way the apache engines works with php. In truth, this isn't a php question but an apache one (in case you're using apache, which I will assume)

The simplest way of doing this, is to add a .htaccess with the following contents:

AddType application/x-httpd-php .php .html

This basically tells apache that all .html files should be parsed by PHP, read more about it here.

What you actually saw, I suspect are URL rewrites, read more about mod_rewrite.

Sign up to request clarification or add additional context in comments.

Comments

0

If you can't modify the server's setup, then you're SOL. You have to tell the server that .html files should be treated as PHP scripts. There's no way around this. It won't magically start sending them through the PHP parser unless you tell it to.

On an Apache setup, it's a matter of putting in a configuration directly, such as

AddType application/x-httpd-php .php .htm .html

Comments

0

ModRewrite

RewriteEngine on
RewriteRule ^(.*).html$ $1.php

AddType

AddType application/x-httpd-php .htm .html

Comments

-2

I worked around the problem by adding a config variable which is then used in a string replacement call to replace an export-generated string with one which someone can update in a config file, before burning to CD. I can get away with this because the string replacement is essentially the only PHP in these HTML files. I'll close this question after... leaving for anyone to check up on/read about quickly.

1 Comment

This answer solves the OP's issue (yes, I realize that it is the OP posting) but it does not answer the question. As this question turns up in searches with a useless selected answer I am downvoting the useless answer. Sorry, Danjah, but it's for the best of the site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.