Your First PHP Program
Now you know what is PHP. Lets start creating our first PHP program.
PHP Programs are just text files. You can create your PHP script in any ASCII text editor like Windows Notepad.exe or Edit Plus. Do not use Rich Text editor like MS Word, MS Write or Page Maker. I recommend using Edit+ available at www.EditPlus.com
All PHP Program file names should end with .php
Example: first_program.php, test.php
To create your first PHP Program, start your Text Editor and create a new file, put following content
<HTML>
<HEAD>
<TITLE> My First PHP Program </TITLE>
</HEAD>
<BODY>
<?php
echo "Hello World";
?>
</BODY>
</HTML>
Save the file as test.php
Now you have your first PHP Program ready to run. PHP is a server side program. So to run it, you need to upload it to your web server and call it.
http://your-web-server/test.php
If you are running on local web server, put the file in web servers DocumentRoot and access it through web server like
http://localhost/test.php
The program will show "Hello World" on the browser.
Let's Look into the code
Every PHP script start with <?php and end with ?>
echo command is used to print string "Hello World" to browser.
All PHP command ends with a semicolon ( ; )
Back to Home
|