Remember, PHP commands are essentially long HTML tags. So, a PHP "program" looks like this:
<?php // PHP Commands go here ?> |
Note that every PHP command ends with a semicolon. Although it is unnecessary from the PHP interpreter's point of view, PHP code is usually more readable if it is minimally formatted. At start, that means that each command should go on a separate line and that extra blank lines should be placed where necessary to make the code more readable.
One of the purposes of computer languages is to make programs understandable by people other than those who wrote them. One useful technique is to use comments, where appropriate. A comment is ignored by the computer, but provides a human with useful information. In PHP, a comment is preceded by //, as in the example above. (Note that you need a // for each comment line.)
Perhaps the most fundamental PHP command is echo. The echo command outputs whatever follows it to the hypertext document in which the PHP code is enclosed. (Recall that the ultimate result of a PHP program is a hypertext document, which is interpreted by a web browser.) Here is an example of a PHP program:
<html> echo "This is output from the echo command."; ?> |
And this is what the output looks like:
|
Here we go . . . This is output from the echo command. |