1.1.1 What Is an HTML Document?
HTML is an acronym for H yper T ext M arkup L anguage. HTML documents, the foundation of all content appearing on the World Wide Web (WWW), consist of two essential parts: information content and a set of instructions that tells your computer how to display that content. These instructionsthe markup, in editorial jargoncomprise the HTML language. It is not a programming language in the traditional sense, but rather a set of instructions about how to display content in a Web browser. Ideally, online content should look the same regardless of the browser being used or the operating system on which the browser resides. This goal of complete platform independence is achieved only approximately in practice.
Every HTML document should contain a minimum of four elements:
These elements define the essential parts of an HTML document : the document itself, a heading section, a title section, and a body. All four elements should be included even if they dont enclose any content. Every HTML element is defined by one or two tags usually a start tag and an end tag. Tags are always enclosed in angle brackets: < >. End tags start with a slash (/). A few HTML elements have only one tag.
The four basic elements are organized as follows within an HTML document:
The html tag encloses all other tags and defines the boundaries of the HTML document. We will return to the other tags later. The indenting used to set off pairs of tags is optional, but it makes documents easier to create, read, and edit. This style is part of good programming practice in all languages.
HTML documents are usually used as to distribute information for access on the Web. However, for the purposes of this book, HTML documents will be used along with the PHP programming language to create an environment for solving a wide range of computing problems.
Good programming technique often involves separating the input/output ( I/O) interface from the underlying calculations that do the work of a program. The HTML/PHP programming environment provides a conceptually elegant means of implementing this strategy. An HTML document provides the I/O interface and PHP handles the calculations. An advantage of HTML is that it provides a wealth of interface possibilities that far surpass those of older text-based languages.
1.1.2 How Do You Create HTML Documents?
Because HTML documents are just text documents, they can be created with any text editor. Even Windows very basic Notepad application is a workable choice for simple tasks. Once HTML files have been created, you can open them in your computers browser, hopefully without regard to which browser you are using. As long as you give such documents an .htm or .html file name extension, they should automatically open in your browser when you double-click on the file name. Although Windows documents are no longer restricted to three-letter extensions, a convention dating back to the pre-Windows days of MS-DOS operating systems, the three-letter .htm extension is often used on Windows systems. The four-letter . html extension is commonly used on UNIX systems. However, either extension is perfectly acceptable.
There is one other consequence of using Windows computers for creating all the code examples in this text: Windows file names are case-insensitive, while on UNIX systems, all spellings, including file names and commands, are case-sensitive. In Windows, you can name a document newDocument.htm . Later, you can spell it newdocument.htm , NEWDOCUMENT.HTM , or any other combination of uppercase and lowercase letters and it wont matter. On a UNIX system, that file will be recognized only with the original spelling.
Although you can create text (and, therefore, HTML) documents with a full-featured word processor such as Microsoft Word, this is not recommended. When you save a word processor document it no longer contains just the text you have typed, but also all the layout and formatting information that goes with that document. You can choose to save a document as just text with an .htm extension, but it is easy to forget to do this.
Microsoft Word and other modern word-processing applications can also format any document as an HTML document. However, this is also not recommended. These converted documents may include a huge quantity of extraneous information and HTML instructions that make the resulting file much larger and more complex than it needs to be. (To see this for yourself, save a Word document as an HTML document and then look at the result in a text editor such as Notepad!)
RTF ( rich text format) documents are also unacceptable, as they still retain some formatting information that is inappropriate for an HTML document. Any document that contains smart quotes rather than " straight quotes " can also cause problems, because smart quotes may not be displayed properly by browsers. (This is much less of a problem on current browsers than it used to be.)
There are commercial Web development tools that allow you to create Web pages without actually knowing anything about HTML. These applications are not suitable for use with this book. The obvious reason is that the primary purpose of the book is to show you how to write your own HTML documents to be used as an interface to a PHP file. Also, these applications may create HTML files that are much larger and more complex than they need to be. Such applications are better suited for Web development projects that involve a lot of the other bells and whistles that make commercial Web pages attractive.
Creating an HTML document that does what you need it do inevitably involves switching back and forth between a text editor and a browsermaking changes and observing the effects of those changes. A good editor should allow you to move back and forth quickly and easily between the source document and its display in a browser when you make changes. It is certainly possible, but not particularly convenient, to do this with a simple text editor such as Notepad.
There are many commercial software tools whose purpose is to facilitate writing and editing HTML documents by integrating document creation, editing, and viewing. As noted above, some of them are intended for large and complicated projects and may be overkill for use with this book. For many years, I have used Visicom Medias freeware AceHTML . This software is no longer available, but there are other freeware alternatives which provide automatic color-based text formatting, coding tools, and an integrated browser that makes it easy to create and edit HTML and PHP documents.
Although it shouldnt make any difference which browser you use, it is worth noting that all the HTML documents displayed in this text come from either AceHTMLs internal browser or Mozillas Firefox, which is the default browser on the authors Windows computers.