How To

How to Merge PHP with HTML

Contributor
By eHow Contributing Writer
(2 Ratings)

PHP is a handy web programming language that you can use with HTML. You either can add a section of PHP code to an existing HTML document, or you can add HTML code to a PHP document. Just follow these steps.

Difficulty: Easy
Instructions

    Add PHP to an HTML Document

  1. Step 1

    Begin your document as usual with the standard HTML tags.

  2. Step 2

    Open a new tag by typing a left alligator bracket followed by a question mark and the letters "php:" don't close the tag yet.

  3. Step 3

    Add your PHP code in the following lines. Don't forget to document what you're doing by adding comments after two slashes.

  4. Step 4

    Close your PHP tag by typing a question mark followed by a right alligator bracket.

  5. Step 5

    Finish your document by adding the rest of the HTML tags and content.

  6. Include HTML in a PHP Document

  7. Step 1

    Create a PHP document as usual.

  8. Step 2

    Use a print statement such as "echo" to tell the server to display the upcoming content as text when it processes the code for the browser.

  9. Step 3

    Let the server know you'll be using HTML next by typing a left alligator bracket and the characters "html info" then a closing (right) alligator bracket.

  10. Step 4

    Close out the PHP by typing a question mark and right alligator bracket if you want, or leave it open. This usually won't make a difference.

  11. Step 5

    Open the HTML portion of your code in the usual way by typing "html" inside right and left alligator brackets.

  12. Step 6

    Add the rest of your HTML code.

  13. Step 7

    Finish up by typing a closing HTML tag (left alligator, forward slash, "html," right alligator). Close your PHP if you haven't already.

Tips & Warnings
  • When using "echo" to signify the proper processing of HTML, remember to surround the HTML section of the code (including the "html info" tag) with double quotes.
  • Don't forget to end every PHP statement with a semicolon.

Post a Comment

Post a Comment

Have you done this? Click here to let us know.

I Did This

Related Ads

Internet
Virginia DeBolt,

Meet Virginia DeBolt eHow’s Internet Expert.

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US

Demand Media
eHow_eHow Technology and Electronics