Introduction in PHP.

Usual PHP file is practically an HTML text with included PHP scripts. To include a PHP script inside an HTML document we need to write all the PHP commands we want to run between <?php and ?>. Also there is a shorter form of the opening construction with word php omitted:
usual HTML commands
<?
 PHP commands
?>
again HTML commands
Like JavaScript we can include as many PHP script in our document as we want. However, there are two important differences between JS and PHP: We also would like to introduce a simple PHP command echo. This command prints its arguments. Thus, the following three lines of code produce <h1>Hello</h1> in the result file.
 echo "<h1>";
 echo "Hello";
 echo "</h1>";

Comments in PHP language

Like always we start talking about new script language by introducing the most important part of any language -- comments. PHP supports three types of comments: Example:
<?
 // this line is commented
 echo "Hello";
 /*  these three 
     lines are also 
     commented  */
?>

Variables in PHP scripts

Variable in PHP are very much like ones in JavaScript. Except one small detail -- the names of all variables are to start with $. To describe a new variable all you need to do is to initialize it by usual assignment operator:
$a = "this is a string";
$b = 12; // this is going to be an integer variable
$c = 12.4 # this is double
You do not need to specify type of a new variable. It will be chosen automatically depending on the value you assigned to the variable. You don't even have to say var in front of a new variable like we did in JavaScript. If you need a new variable to store some value just assign this value to the variable.

However, with this approach we sometimes need to make sure that a particular variable was defined. There are several functions that work with variables two of them are very simple (but still useful):

Function unset() removes a variable passed as an argument from the memory. After calling

 unset($name);
variable $name no longer exists. Function gettype() takes a variable as its argument and returns a string containing a type of the variable. For example, the following PHP code
prints types of each declared variable according to the value we assigned to it. In this example also please pay attention that the string each echo command is printing contains three parts - two constant strings and result returned be the gettype() function. To add all three pieces together we use dot operator, which concatenates two strings into one.

Passing arguments to PHP scripts

Now we would like to discuss how we can pass variables from an HTML form into an PHP script. To do this we have to do several things: If we did only the first two of these steps, then inside the script we can access each argument by accessing $_REQUEST["argument_name"]. If we used method POST, then we can access arguments by $_POST["argument_name"]. Where argument_name is the name of the argument which value you want to get typed exactly the same way you did it in the HTML form (PHP is case sensitive).

Let's consider a simple example. We'll create a small HTML form with only one input text element and a submit button. We will name the element myname and specify action parameter of the form as script.php:

<form action="script.php">
 Enter your name:  <input type=text name="myname">
 <input type=submit value="Execute script">
</form>
Then script.php may look like this:
<html>
<body>
<?
 $myname = $_REQUEST["myname"];
 if( isset($myname) )
   print "Your name is $myname
"; else print "You are too lazy to type your name!"; ?> </body> </html>
In this section we will not discuss why we should access the arguments passed to PHP script by accessing such strange things as $_REQUEST or $_POST. We will postpone this discussion till the moment we'll get to know what PHP arrays are.

Here you can find an example that shows how to pass data not only from input text element, but also from select list, radio buttons, and check boxes.

Date and time functions in PHP.

Sometimes our PHP script has to know the current date and/or time to behave properly. PHP has more than 10 different functions to work with date and time. In this section we will discuss only three of them: