Sending Data to the Browser

I l @ ve RuBoard

Now that you have created your first PHP script, it's time to make it actually do something. As discussed in the introduction, PHP tells the server what data to send to your Web browser. For starters, you will use the phpinfo() function to create our data. This function, when called, will send a table of information to the Web browser itemizing the specifics of the PHP installation on that particular server.

To add the phpinfo() function to your script:

  1. Open your first.php script in your text editor, if it isn't already.

  2. Put your cursor between the PHP tags ( <?PHP and ?> ) and create a new line by pressing Return).

  3. On the new line, type phpinfo();.

  4. Change the title of the page by replacing First with Test in line 3 of the HTML (Script 1.2).

    Script 1.2. Since we will save this as a different file, we also changed the HTML title line when we added the phpinfo() function.

    graphics/01sc02.gif

  5. Save your script as test.php.

Every statement within PHP code must end with a semicolon (;). Forgetting to do so is a common cause of errors. You can put multiple statements on one line, with each separated by its own semicolon. For the sake of clarity, however, I would not recommend it.

A statement in PHP is an executable line of code, like print() or phpinfo(). The semicolon concluding these lines are the equivalent of telling PHP to go ahead and execute the command. Conversely, comment lines, the PHP tags, control structures (conditionals, loops , etc.), and certain other constructs I'll discuss in this book do not merit a semicolon. Each of these aspects of PHP do not do anything in and of themselves so much as dictate the circumstances for the statements to follow. That is to say: the PHP tag only indicates that PHP code is to follow; comment characters render text moot, and so forth. Thus, in general, a semicolon concludes a specific action, while no semicolon is required for constructs that create conditions.

Tip

For better or worse , PHP is rather liberal when it comes to case sensitivity of built-in functions like PHPINFO(). PHPinfo() and PHPINFO() will net the same results. Later in the book (for example, Chapter 2, Variables) you will see examples of instances where the word case will make a crucial difference. HTML, in contrast, is entirely case insensitive.


Tip

Phpinfo() is an example of a built-in function which comes standard in PHP. To learn more about functions and how to create your own, see Chapter 9, Creating Functions.


Tip

You will find it handy to have a copy of the test.php file around. You can use this to check the PHP capabilities of a new server or see what features are supported, such as databases, GIF building, etc. You can also use this file to experiment with different extensions and learn which ones the server will process correctly and which it will not.


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