PHP Snippets: Echo

PHPThis post is part of the PHP Snippets series where I will be covering the basics of developing in PHP.

Almost everything you write in PHP ill have an output to the user; the simplest way of doing this is to use the in-built echo function (which you can use with or without parentheses).

The below example is a simple echo to output one line of text:

echo 'Hello world!';

You can output multiple lines of text, which you would do with multiple echo function calls:

echo 'Hello world!<br />';
echo 'This is a simple PHP example.';

Notice though, there is a HTML break line tag <br /> included at the end of the first line; if this wasn’t present, then both lines would be output on the same row.