PHP Tutorial – Part 2 of 5

Published on Mar 20, 2007   //  Tutorials
Off

PHPIn Part 1 of our PHP Tutorial series we covered how to use PHP and HTML together and use the print command.

In this one we will learn to use variables and use the date command. If you have never programmed before then the concept of a variable may be new to you. A variable is like a box in which you can store something for later. For example you may store the date or name of a person in a variable so that you can use it later in the code. A quick example is to open notepad again and add the following code then save it as a .php file and upload to your site:

[code='php'] $variable1="Bob";
$last_name="Smith";
Print("Hello my name is $variable1 $last_name");
?>[/code]

In the above example there are 2 variables ($variable1 and $last_name). When using a variable the name needs to start with a dollar sign ($) and not have any spaces in it. If you are setting the variable to be text then you will need to use an equals with the text in brackets. Remember that all lines in PHP end with a semicolon (;).

A variable does not have to be text but can be a function. For example if we wanted to display the date we could do the following:

[code='php'] $now=date("F j, Y, g:i a");
Print("The date today is $now");
?>[/code]

Again be sure to save the file with a .php extension and upload it to your site. In this example you should see the current date.

Stay tuned as we will continue this tutorial with more details on using PHP.

PHP Tutorial – Part 1 of 5

Published on Mar 12, 2007   //  Tutorials

PHPWhat is PHP?
PHP stands for PHP Hypertext Preprocessor. PHP is a programming language which allows you to create web applications. PHP is widely used by many developers and is a very easy language to learn to use. There is lots of documentation on PHP at there site on how to use PHP.

Using PHP and HTML Together
You can mix PHP and HTML together in on page. PHP complies or runs on the server before sending to the browser so mixing PHP together with HTML is not a problem. For PHP to work on our servers you will need to save your files with a .php extension instead of a .html (or .htm).

Try the following example. Open up your notepad and enter the following:

 [code='php']



[/code]

Save the file as example.php and upload it to your site. You will see that it outputs in bold Hello World. The print command lets you simply display text or variable on the screen. Notice how the PHP is encased with <?php and ?>. Also make note that after each php line you should have a semicolon.

Stay tuned as we will continue this tutorial with more details on using PHP.

Page 2 of 212