Sunday, July 19, 2009

Learn PHP on 15 Minutes

Step 1:

To be able to execute PHP scripts, you need at least a working PHP installation+ web server. Linux, Apache, MySQL and PHP are the best combinations. PHP also can run under Microsoft Windows, too.

PHP installation and configuration can be made easy with tools such as Apache2Triad or XAMPP which automate web server and PHP installation.

PHP script is stored in text format file so you need text editor. Notepad and Notepad++ are enough for your PHP development needs. However, you may opt to invest in more advanced tools such Dreamweaver or Eclipse.
Step 2:

PHP script is anything between pair. You can also use . The first is most widely used.

print '

Hello this is my first script


Output of the following code will be same as the previous code:

print '

Hello this is my first script


Step 3:

The power of PHP lies on the capability to change how HTML code will output. The following code will output different HTML codes when you change the name.

print '

Hello '.$name.' this is my first script

'; ?>

Save this script as welcome.php in the document root directory (for Apache web server, this is usually htdocs directory). Open your web browser and type http://localhost/welcome.php?name=Zamrony

Step 4:

$_GET is a predefined variable which stores lists of parameters passed to the script. It is an array. If you change http://localhost/welcome.php?name=zamrony&country=Indonesia, $_GET will contain more items.

print '

Hello '.$name.' from '.$acountry.' .
this is my first PHP script


It will print Hello Zamrony from Indonesia. This is my first PHP script.

Step 5:

$aname, $acountry and $_GET are all variables in PHP. Any variables in PHP should be prefixed with dollar sign. Variable names must only contain alphanumeric and underscore characters where the first character in variable names should be alphabet characters or underscores.

This is invalid variable name:


This is valid variable name:


PHP is case sensitive. Variable $kk is not $KK.

No comments:

Post a Comment