Baby Steps in PHP
Many times, in programming forums, somebody asks for a tutorial or how to start programming in PHP. Programming your first script in PHP can bea frustration. So I created this simple tutorial for newbies and beginners.
First to one should have an environment to let it run. Unlike a normal static HTML file that you could double click to view it. PHP needs the PHP interpreter and a web server. If you are developing in windows, WAMP (Windows , Apache, MySQL and PHP) is the package download. Get it here. Install it and you will now have a full PHP development platform plus MySQL to boot. For us using linux, this is already included in most distributions.
After installing WAMP and configuring it. You can test the PHP if it is working well. This is done by creating a file test.php, with only the following contents:
<? phpinfo() ?>
Save this and put it in the web server’s html directory. Open your browser and open the file via network not by double-clicking it. You should see here the PHP version and the installed configuration. We now have our working environment and we can start programming.
Let’s create a new file first.php with a pure html content:
<html>
<body>
Hello, World!
</body>
</html>
Open this file on the browser via the web server and see the result. As you see, PHP scripts can show HTML directly.
Then lets then change our first.php program to show a dynamic content. Take notice that the PHP program codes is only placed between the <?php and ?> tag. Outside this tag, you can put any HTML codes you like.
<html>
<body>
<?php
echo “Hello, World!<br>”;
echo “Today is ” . date(”F d, Y”) . “.”;
?>
</body>
</html>
This is great! Our program now will display the current date. Opening this page again tomorrow will change its content.
So what’s next? In other programming languages, one can input something to interact with it. In PHP, we can do this also. But it is quite different here. We will use HTML forms to do this. If you know CGI, this is a breeze.
To actually try it, we create another file input.php. This is the content:
<html>
<body>
<form method=POST>
What is your name?
<input type=text name=’Name’>
<input type=submit value=’Submit’>
<br>
<?php
echo “Hello ” . $_POST[’Name’] . “!”;
echo “<BR>Today is ” . date(”F d, Y”) . “.”;
?>
</form>
</body>
</html>
Here, our program asks for an input. When the SUBMIT button is clicked, the value type in “Name” will be stored in $_POST[] array. Then this can be used in the script, thus displaying $_POST[’Name’].
Congratulations! We have now done the first small steps in learning PHP. On the examples above, it is demonstrated how to make a simple PHP script. But still further reading and learning are needed, such as basic HTML, DOM and Javascript. Flow controls on PHP, object oriented classes and session management should also be learned for serious PHP programmer wannabees.
The example PHP progams can be download here.

