Php Basis

Posted in Tutorials, Php by Rz on the October 31st, 2005

This tutorial explain the Php basis. The objective is to get you familiar with Php commands.

» So what is the aim of those < ? ?> ?
Php is an “Interpreted” language. This means that Php is NOT compiled, it is parsed at runtime (the time when the script is run. ex : user visits the page).

All Php code is enclosed within “< ?" and "?>“. Functions (text that causes action in the script), are ended by the semicolon (”;”). Comments (or escaped text) are as follows:

#Comments => shell style comment
//Comments => standard comment
/* Comments */ => C-style comment

» What does a Php page look like ?

< ?
$name = "RZ::DESIGN";
echo "<html><head><title>Php Tutorial</title></head>”;
echo “<body>”;
echo “Welcome in $name”;
echo “</body>”;
echo “</html>”;

This code just write the text : Welcome in RZ::DESIGN in a standard html page.

Now lets take a look at this. First, we initialize the Php interpreter. On the second line, we assign the variable “$name” to the value “RZ::DESIGN”. This is done by first giving the variable a name.

All variables (with the exception of constants, which you need not to worry about) start with the dollar sign (”$”). After we give the variable a name, we assign it a value, with the Assignment Operator (”=”). The value can be enclosed in either double or single quotes. Use double when you want to invoke “Variable Interpolation”. This means that if a variable is found in between ” and “, the value will be printed. But, if you use single quotes, the values will not be printed, instead, the variable name will be printed.


< ?
$variable = "Here's the variable";
//Next line will print : Where is the variable ? Here's the variable;
echo "Where is the variable ? $variable";
//Next line will print : Where is the variable ? $variable;
echo 'Where is the variable ? $variable';

Next, we use the echo function. There are many ways to display text in Php, echo is the most common. We do four lines of the echo statement to demonstrate how PHP can be integrated with Html. The first line prints the head and title information, the second line starts the body tag, the third line prints the text “Welcome in RZ::DESIGN”, and the fourth line closed the Html. Finally, we end the script, closing the Php tag.

» Conclusion
Now you understand what a sample Php page looks like, and how one works. You have learned about variables, the echo statement, and variable interpolation.

If you get confused, refer back to the manual (