By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

PHP Echo

PHP echo is a language construct, it is used to output data from PHP.

Created: 2012-11-17 12:43

The echo language construct is not really a function, but people often think of it as a function. PHP echo is used to output data, usually to a web browser.

PHP echo examples

Below are a couple examples using echo to output some text with a few linebreaks.

<?php
  echo 'This is line 1
This is line 2
This is line 3';
?>

The linebreaks will not show up in the browser, since the default content-type header value is text/html – you will either need to change it to text/plain – or use HTML br, or paragraph elements.

See also: List of Content-types

Another way to add linebreaks is to use backslash "\" combined with n, which represents a linebreak in PHP – using this method also requires the use of double quotes instead of single quotes.

<?php
  echo "This is line 1\nThis is line 2\nThis is line 3";
?>