Documents that can be viewed by a web browser are called hypertext documents. (To fetch such a document, your browser uses http:, hypertext transfer protocol.) Hypertext documents are ordinary text documents that you could edit in any text editor. However, they contain tags, which are special combinations of characters that tell the web browser to do something, for example, to make certain text bold or to insert a picture. The collection of tags and other features of hypertext documents is called the hypertext markup language, or HTML, and most hypertext documents have HTML or HTM extensions (the shorter extension generally is for older operating systems that could only handle three-letter extensions).
Here is an example of an HTML document (note that I had to use special tags to tell your browser to just show you the text, and not interpret it). If you want to view the HTML source for a web page you are currently viewing (including this one), in the "View" menu of your browser, click on "Source."
|
<html> <center><b><font
size=+1>Homework 4</font></b> <p>In this
assignment, you are to create a personal web page. I recommend <br> <br> <li> <li> <li> <li> <li> <li> <li> <li> <li> <li> <br> </ol> <li> <br> <br> |
Here's the result: html_sample.html.
The HTML tags all begin with < and end with >. Most tags come in pairs, with the second tag the same as the first except for a leading /. For instance, above you can see a number of list items. Each item begins with <li> and ends with </li>. There are six main tags that every hypertext document has: <html>, </html>, <head>, </head>, <body>, and </body>. Accordingly, the simplest hypertext document looks like this:
<html> <head> </head> <body> </body> </html> |
The initial tag, <html>, tells your browser that this is a hypertext document. The tag <head> tells your browser that certain information about your document is coming (such as, the title of the document, the author, and other things that are not displayed in the browser window). The tag </head> tells your browser that the header is finished and <body> tells your browser that the part of your document to display is coming next. Between <body> and </body> is where all the stuff goes which is actually displayed in your browser window. Finally, </body> tells your browser that its reached the end of the body, and </html>, the end of the hypertext.
PHP (Hypertext Pre-Processing) is basically one big HTML tag. It begins with <?php and ends with ?>. In between the <?php and ?> are commands to the web server, where the web page is located.
Let's back up a minute. When you type a url: into your web browser or click on a link, here's what happens: Your web browser sends a request over the Internet for the web page. The request is addressed to a web server, which is a program running on a computer somewhere, which has web pages on its hard drive. The web server gets the request and sends back the hypertext document your browser requested, along with pictures and other things that should be displayed with the document.

The hypertext document is written in HTML, a language your web browser understands. The HTML tags in the hypertext document instruct your browser how to display the document and what to include in the way of pictures and the like.
PHP, by contrast, is a language that is interpreted by the web server that sent the document to your web browser. PHP commands tell the web server to do certain things, including, usually, to insert additional HTML commands into the hypertext document. Therefore, your web browser never sees the PHP.
If PHP simply produces HTML, then why do we need it? The beauty of PHP is that it can change the HTML it produces based upon input it receives and processing it does.
How does PHP receive input? There are some HTML tags which are designed to get input from a user. These tags specify the construction of forms that the user can fill out. Usually, the user then clicks on a button to submit the information on the form. HTML tags for forms can specify that the information in the form be sent to PHP for processing.
To summarize, then, PHP is a bunch of commands embedded in an html tag; the commands are processed by a web server which replaces them with HTML code; and your web browser displays the resulting hypertext document. To let the web server know that there are PHP commands to be interpreted, hypertext documents containing PHP usually have the file extension php.