“Hello, World!” in PHP

89

Every programming language has it’s basic Hello, World! script. PHP has no exception. It is a simple script that only displays the words “Hello, World!” Let’s see “Hello, World!” in PHP.

So how to write this most basic of computer programs in PHP? The two simplest ways are using print and echo, two similar statements that are more or less the same. Both are used to output data to the screen. Echo is slightly faster than print. Print has a return value of 1 so it can be used in expressions, while echo has no return value. Both statements can contain HTML markup. Echo can take multiple parameters; print takes one argument. For the purposes of this example, they are equal.

<?php
Print “Hello, World!”;
?>

<?php
Echo “Hello, World!”;
?>

In each of these two examples, the <?php indicates the start of a PHP tag and the ?> indicates an exit from PHP. These entrance and exit tags identify the code like PHP, and they are used for all PHP coding.

Get real time updates directly on you device, subscribe now.

Subscribe to our newsletter
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time