Lesson 1: PHP Basics (PHP Hello World)

Written by admin

Topics: Lessons, PHP Basics

Do you want to learn php in 24 hours? 

The journey starts with the first step.  When most programmers start learning a new language they start with what is called a “Hello, World!” program.  This is a simple program with the goal of printing the text “Hello, World!” to the screen.

While the most useful way to write the “Hello, World!” program might be for a real web page, let’s start even simpler.  Go to codepad and select the radio button for “PHP”.

Paste the following code into the codepad window and click submit:

<?php
  print "Hello, World!";
?>

In the output section of codepad you should see Hello, World!. Congratulations! You’ve just written your first php snippet.

Code Review

PHP always starts and ends with <?php and ?> respectively. This is used to tell the interpreter this is PHP as opposed to, say, HTML.

The rest is more straight forward. The print command prints the text in quotes. Finally every command must be followed by a ;. This allows you to write a multi-line command without confusing PHP: PHP will still know where the end of the line is!

Back to Learn PHP in 24 Hours for more fun :-)

5 Comments Comments For This Post I'd Love to Hear Yours!

  1. Rowery says:

    Hi! Are you going to post more lessons?

  2. admin says:

    Thanks for the feedback. I will certainly post more, I’m just glad to know people are using this resource.

    I’ll try to post another lesson this week.

  3. Greg Keane says:

    Just found this page through a Google search, I hope this works I want to be able to build a basic PHP site.

  4. C-raz says:

    Hi there, thanks for setting this site up. Learning thru right now hopefully I can create awesome php was wondering why most people did not really explain the link between php, sql, and a webserver. How information is stored and where’s the link. Will be good for beginners like me maybe you can include a section on that with a simple example. :)

5 Comments Trackbacks For This Post

  1. Lesson 2: Comments and Variables - Learn php in 24 hours

Leave a Comment Here's Your Chance to Be Heard!