PHP is a scripting language used by Web developers to add dynamic functionality and interactivity beyond what is available using a simple markup language such as HTML. PHP isn't actually seen by a Web browser. Instead, it relies on HTML to send and display the data it generates. PHP can exist side-by-side to HTML code, or it can be used to generate the code dynamically on the fly. Converting an existing HTML document to PHP code involves structuring the PHP code blocks and writing PHP script to generate lines of HTML.
- Skill level:
Other People Are Reading
Rename the HTML file. If the file contains the extension of ".html" or ".htm," the Web server will attempt to interpret the file as pure HTML unless the server has been specially configured. Using Windows, rename the HTML file so it ends in ".php" and the browser will correctly identify it.
Embed the HTML within the PHP code. PHP and HTML can easily exist within the same file. In most cases no modification needs to be done to the HTML code. At the very beginning of the file enter "<?php" to begin the PHP code block. Inside the block include whatever PHP code you wish. When you are ready to begin HTML code again, enter "?>" to close the block. You can easily switch back and forth between blocks of PHP or HTML code as many times as needed throughout the file.
Use the Echo function to have PHP generate HTML code. If you need portions of your HTML code to be generated by PHP -- to display the value of a variable, for example -- you will need to use Echo to generate the HTML. While you are within a PHP code block, type (Echo ") to begin the Echo command. Enter you HTML code however you want. If you need to insert a variable, break out of the echo with a (".), insert the variable name ($_VARIABE) and re-enter the Echo (."). When you are finished with the Echo, use (";) to close the function. An example of an Echo function will look like "Echo (Hello my name is ".$_Name .";" without the quotation marks).
Tips and warnings
- PHP files that generate Web pages using HTML code need to contain all the necessary code for standalone HTML files such as the header information.
- Files containing PHP code must be located on a Web server with PHP installed for it to display properly. Running a PHP file directly from your hard drive will have no effect.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for