0
0
PHPprogramming~5 mins

First PHP program (Hello World)

Choose your learning style9 modes available
Introduction

We write a simple program to show how PHP works and to see a message on the screen.

When you want to check if PHP is installed and working on your computer.
When you start learning PHP and want to see how to write and run a PHP script.
When you want to display a simple message on a web page.
When you want to test your web server setup with PHP.
Syntax
PHP
<?php
  echo "Hello World!";
?>

PHP code starts with <?php and ends with ?>.

The echo command shows text on the screen.

Examples
This prints the message Hello World! on the screen.
PHP
<?php
echo "Hello World!";
?>
You can use single quotes or double quotes for text.
PHP
<?php
echo 'Hello World!';
?>
Comments start with // and are ignored by PHP.
PHP
<?php
// This is a comment
 echo "Hello World!";
?>
Sample Program

This program shows the message Hello World! on the screen when run.

PHP
<?php
// This program prints Hello World!
echo "Hello World!";
?>
OutputSuccess
Important Notes

Make sure your file is saved with a .php extension.

Run the program on a web server or using the PHP command line to see the output.

Summary

PHP programs start with <?php and end with ?>.

The echo command prints text to the screen.

"Hello World!" is the classic first message to learn any programming language.