This PHP Hello World tutorial will teach you how to use the PHP echo
and print
statements to display output in a web browser. The primary purpose of this example program is to explain to beginners how to print on PHP.
Display String as Output
Example:
The following example shows how to use an echo statement to display "Hello World!".
<?php
echo 'Hello, World!';
?>
Program Output:
Hello, World!
Display HTML Code as Output
Example:
The following example shows how to use echo statements to display an HTML Code.
<?php
echo "<h1>Page Heading</h1>";
print "<p style='font-weight:bold; color:blue;'>This is a paragraph text styled with CSS.</p>";
?>
Program Output:
Page Heading
This is a paragraph text that is styled with CSS.
The print
and echo
both are language constructs, not functions. These two statements are substitutes and do exactly the same, except that the print
statement always returns 1.