|
|
|
Basics
of PHP
This tutorial explains the basics of php. The objective is to
get you familiar with the commands.
Might as well begin with the <? ?>
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:
CODE |
#Comments => shell style comment
//Comments => standard comment
/* Comments */ => C-style comment
|
» What does a Php page look like ?
CODE |
<?php
$name = "XTASYGAMING";
echo "<html><head><title>Php
Tutorial</title></head>";
echo "<body>";
echo "Welcome in $name";
echo "</body></html>";
?>
|
This code just write the text : Welcome in XTASYGAMING 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 "XTASYGAMING". 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.
Example:
CODE |
<?
$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 XTASYGAMING", and the fourth line
closed the Html. Finally, we end the script, closing the Php
tag.
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 (www.php.net) or
contact me.
Tutorial By Xtasy
|
|