SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Oct 2005
    Posts
    284
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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.
    Code:
    	</form>
    	<p id="msg"><!-- anymsg --></p>
    </div>
    </body>
    </html>
    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?

    Regards,

    Brian

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    I'm afraid I don't quite follow you.
    Why would you have to duplicate code?

  3. #3
    SitePoint Addict
    Join Date
    Oct 2005
    Posts
    284
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    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).

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Grnadpa View Post
    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 www.yoursite.com, 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.

  5. #5
    SitePoint Addict
    Join Date
    Oct 2005
    Posts
    284
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •