Starting PHP Week 1

Contents for PHP

  1. Starting PHP Week 1
  2. PHP Week 2
  3. PHP Week 3
  4. PHP Week 4
  5. PHP Week 5

I started to learn PHP and my first program was the well known Hello World. The first line opens the program. The second line is a comment, meaning the computer skips that line, and it is only for me and other users to use. The third line tells the computer to write what is put in between the brackets, '\n' being a return. The fourth line tells the computer to also write what is in the brackets. The last and fifth line ends the program.

//Hello World
echo "\nWelcome back Your Awesomeness\n";
echo "How are you?\n\n";


Fany-Savinas-Mac:PHP Fany$ php hello.php
Welcome back Your Awesomeness
How are you?

I also made another program, entitled Hello User. The first line opens the program. The second line creates a variable. A variable is like an empty box in which information can be put. Only one piece of information can fit at a time. Another way of looking at it, is that a variable is a blank ready to be filled up. On the second line, our variable is $firstname. The next part tells the computer what to place into the variable. I told the computer to place the argument number 1. In PHP, arguments start with 0, meaning argument number 1 is actually in the second position. Argument number 0, in the first position, would be the name of the program. Line three does the same as line two, only with a new variable named $surname and argument number 2, which is in third position. The fourth line tells the computer to write Hello along with the suitable arguments place in the command. Line 5 ends the program.

echo "\nHello $firstname $surname \n\n";

Fany-Savinas-Mac:PHP Fany$ php hello_user.php Fany Savina
Hello Fany Savina

This entry was posted in Computing and tagged , , . Bookmark the permalink.

Leave a reply