How to Merge PHP with HTML

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.

Instructions

  1. Add PHP to an HTML Document

    • 1

      Begin your document as usual with the standard HTML tags.

    • 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

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

    • 4

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

    • 5

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

    Include HTML in a PHP Document

    • 6

      Create a PHP document as usual.

    • 7

      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.

    • 8

      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.

    • 9

      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.

    • 10

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

    • 11

      Add the rest of your HTML code.

    • 12

      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.

Related Searches:

Comments

You May Also Like

Related Ads

Featured