PHP Index

In order to become familiar with PHP programming structures and commands, we will build various PHP pages. Sections of this page will explain each PHP command, provide a link to a working sample, and detail the working sample's PHP code. Let's get started:

Comments

Up to this point we have rarely commented our HTML. Well, it is now time to start commenting your PHP. We comment in order to speed up maintenance of our code. After not working with a bit of code for a long time, you will have a hard time recognizing what the code means, so COMMENT your code! =).

PHP allows you to comment your code using three methods:

# This is a single line comment.

// This is also a single line comment.

/* This is a
multi-line
comment*/

For example: comments.php


<html>
<head>
<title>comments.php</title>
</head>
<body>
<?php
/*
Date: 01/31/2006
Programmer: Manuel Chagoyan
Purpose: To add up the amount owed to me by my students.
*/

$number1=10//This is the $10 bucks Jenah owes me.
$number2=15//This is the $15 bucks David owes me.
$number3=5;   #This is the 5 bucks Ethan owes me (plus interest).

$total=$number1+$number2+$number3//This creates a variable to hold total owed.

/*
This section prints to the browser.
It concatinates text, html, and php
variable output.
*/


print("<p>The sum of the numbers is ".$total."</p>");

print(
"I have ".($number1+$number2+$number3)." dollars!");

?>

</body>
</html>




In JavaScript, we used // to create single line comments and /* */ for multiline comments.