Monday, November 24, 2008

Lesson 1 : Hello World

Lesson 1 : Hello World

Objective
In the programming world, no matter what language you are learning, “Hello
World” is the first thing that you learn. This lesson will teach you how to create a
PHP file and how to use PHP to print the words “Hello World” on your screen.

Step 1
Open your Text Editing Program. On Windows, you can use the program named
“Notepad”. On a Mac, you can use the program named “TextEdit”.

Step 2
Now we’re going to type a few lines of code. Type the lines just as they appear in
the text below:


Step 3
Now that you have typed the text from the grey box into your window, you need
to save the file. At the top of your screen click File > Save As… and navigate to
the Projects Folder that you created on your desktop.

Step 4
You will need to type in a name for your PHP file. Name this file hello.php.

Step 5
Now that you have saved hello.php to your Projects Folder, it is time to upload it
to your server. Open your FTP Program and connect to your server.

Step 6
Once you are connected to your server, click on hello.php in your FTP Program
and drag hello.php to the main directory on your server. Allow a moment for the
file to transfer.

Step 7
If you have completed all of these tasks correctly, you should be ready to view
your file online. Open your Web Browser, and using your web domain, type in
www.YourWebDomain.com/hello.php. You should see the words “Hello World” in
your Web Browser.

Step 8
If you see the words “Hello World” in your Web Browser, you have successfully
completed Lesson 1. If something seems to have gone wrong, go back and give
it another try.


We just created the simplest of all PHP programs. Now we’ll go line by line to
help understand what we did.
Line 1

Line 2

echo “Hello World”;

This line of code uses the echo command. Whenever you want to display text on
the screen, you use the echo command. The text that you wish to print to the
screen must be enclosed between quotes. The line must end with a semicolon.


Line 3

?>
This will be the final line to every PHP file that you ever create. This tells the
server that the current section of PHP code has come to an end.


Exercise
Now that you can get your file to display “Hello World” in your Web Browser, try
altering the file and make it display a different message.

Conclusion
In Lesson 1 we learned how to output a simple line of text. While this may seem
like a silly and pointless exercise, we will use this as the foundation to build more
useful skills.

No comments: