Sending HTML to the Browser

I l @ ve RuBoard

As those who first learned HTML were quick discover, viewing plain text in a Web browser leaves a lot to be desired. Indeed, HTML was created in order to make plain text more appealing and useful. Since HTML works by adding tags to text, you can use PHP to send HTML tags to the browser, along with our other data.

To send HTML to the browser using PHP:

  1. Open your first.php script in your text editor.

  2. Edit the "Hello, world!" text in line 7 by adding bold and center tags to read print ("<B><CENTER>Hello, world!</CENTER> </B>"); (Script 1.4).

    Script 1.4. By using the print function, you can send HTML tags along with your text to the browser, where the formatting will be applied.

    graphics/01sc04.gif

  3. Upload your script to your server and reload the page in your browser (Figure 1.4).

    Figure 1.4. Our new version of the script, with a little more decoration and appeal . Any HTML tag can be sent to the browser from PHP; just be sure to follow HTML conventions (use closing tags, for example).

    graphics/01fig04.gif

Tip

HTML tags which require quotation marks (e.g., <FONT COLOR ="#000000"> ) will cause problems when printing from PHP, since the print() function uses quotation marks as well. To avoid complications, you escape the quotation marks using the backslash (\). In our example, the statement you would use is print "<FONT COLOR=\"#000000\">";. By escaping a quotation mark within your print() statement, PHP will print the mark instead of interpreting it as either the beginning or end of the print statement itself. I will cover many examples of escaping throughout this book.


I l @ ve RuBoard


PHP for the World Wide Web (Visual QuickStart Guide)
PHP for the World Wide Web (Visual QuickStart Guide)
ISBN: 0201727870
EAN: 2147483647
Year: 2001
Pages: 116
Authors: Larry Ullman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net