Every good web developer needs a reliable server-side programming language like PHP. Here’s a simple script to help you say hello to the world — PHP style!
So you want to learn PHP, eh? Well this is the place to learn it! In this tutorial you will learn how to simply output “Hello World!” to the browser.
PHP Logistics
PHP is a Server-Side Language
Anything you write in PHP the user will not be able to view in the source, because it is a server side language. Only the things that you output to the browser will be viewable. This is very convenient and great, because no one can steal your scripts! Also, it makes a site much more user friendly and quick to use.
PHP Helps Provide User Interaction
With PHP you can create things such as logins, chats, etc. All of these things are fun and exciting, allowing people to have fun with your website.
Saying Hello World!
Initiating PHP
All PHP scripts must start with and end with ?>. Things that start with # act as comments. For example:

Notice how all of the comments must be inside the closing and ending tags of PHP, otherwise they wouldn’t be comments, but rather they would be buffered as HTML.
Using echo to Output to the Browser
To output to the browser you must use the command echo. The syntax is as follows:

There are a few things that should be noticed. First off, the quotations around Hello World! and the semicolon (;) at the end. The semicolon tells the browser to stop the echo command.
Storing Hello World! in a Variable
Similarly, you could store Hello World! into a variable and echo it from the variable instead. Variables in PHP always start with a dollar sign ($). For example:

Notice how there is a semicolon after storing Hello World! into the variable var stopping the action. Also, notice how there is no quotations when we echo this variable.
If you were to put quotations, they would need to be double quotes (”). For example, the previous example could also be written this way:

So those are the simplest versions of the Hello World! script. Next time we will discuss combining strings and variables and more complex variable structures.













February 27th, 2009 at 5:03 pm
Nice work, lots of great information