Join for free

...

/

Hello World

Hello World

This lesson gets you acquainted with the Hello World program in PHP.

We'll cover the following...

Why “Hello World”?

The first program that most aspiring programmers write is the classic “Hello World” program. The purpose of this program is to display the text “Hello World!” to the user.

The “Hello World” example is somewhat famous as it is often the first program presented when introducing a programming language.

Press + to interact
Hello World in PHP
Hello World in PHP

Syntax #

Try running the code below:

Press + to interact
<?php
echo "Hello, World!\n";
?>

The most widely used language construct to print output in PHP is echo.

Alternatively, you can also use print:

Press + to interact
<?php
print "Hello, World!\n";
?>

PHP also provides C-style printf and related functions. Run the following code:

Press + to interact
<?php
printf("%s\n", "Hello, World!");
?>

Now in the next lesson, we will discuss the syntax of the “Hello World!” code in detail to get you familiarized with the basic syntax in PHP.

Access this course and 1200+ top-rated courses and projects.