Better way to substitute values in HTML?

If only to avoid duplicating code / redirects, I don’t want to write an xhtml for original entry and duplicate it with embedded <?php ?> tags should I need to resend it.
(e.g. index.html containing a form that I need to send back with error messages).

What I’ve come up with works nicely, but I wonder if it would qualify as Best Practices.

Here’s an example. In my HTML I position my substitute candidate as a comment.

	<p id="msg"><!-- anymsg --></p>

This way I can use the .html suffix and browsers will honor it.

Now (in this example) I find an error, I simply (1) download the original html via PHP function ‘implode’ and (2) replace the ‘<!-- anymsg –>’ string with my html-formatted error message(s) based on the PHP function substr_replace.

Is that a recognizable way to do it, or is there a more common approach?



I’m afraid I don’t quite follow you.
Why would you have to duplicate code?

Is there a way that the XHTML browser can interpret php code? If not, then a user accessing my domain without specifying “php” will go to the index.htm (or index.html) won’t he/she? So if, upon the user filling in the (initial html) form makes an error, I will have to duplicate the code to put in the custom messages through php don’t I? (Unless I do my validations only through javascript).

Browsers don’t interpret php code. None does. They don’t have to. The php code is interpreted server side, and the resulting HTML/CSS code is sent to the browser.
And if a user goes to your site, suppose, then the index.php should be executed by the server if no index.html exists. This does depend on the server settings I believe, but usually that’s how it works.

Well, you answered my question – my solution is not the generally accepted means to generate html. I am familiar with how to embed a <?php ?> snippet within html as well as heredoc. Just seemed that there should be a less cumbersome way.

Thanks for your help and I’ll consider this thread closed.