Let’s write our very first PHP program. Create a file called hello.php in your local folder with this content:

The code

  • PHP code opens with <?php and closes with ?>.
  • The echo statement prints text on screen.
  • Every statement ends with a semicolon “;”.

For example, <?php echo “Hello world!”; ?> will display the phrase “Hello world!” in the browser.

Good habits from day one

  1. Always end your statements with a semicolon.
  2. Use quotes around your text strings.
  3. Save the file as .php, not as .txt.

Now open http://localhost/hello.php: your message appears, generated by the server.

Key point: echo outputs content, and every statement ends with a semicolon. These are your first reflexes.