How to output (echo/print) content in PHP

PHP: How to output (echo/print) content in PHP

There are several ways to output data/content. I might have forgotten about one of them

1) A php file with any content apart from <?php . Without the PHP opening tag, everything else will be echoed out.

2) echo 'some text'; - a simple echo

3) print ('some text'); - similar to echo

4) <?='some text':?> or <?=$a_variable:?>

5) and via functions such as print_r(12345) or var_dump($something)

What is the difference between echo and print in PHP?

There isn't much difference. The only two differences are that echo does not return any value, and can take multiple arguments (echo($a,$b,$b). print() returns a value of 1 and can only take one parameter. Years ago echo() used to be a bit faster, now it would be so insignificant that it is not worth even thinking about which is faster..

webdevetc profile pic

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This ( is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.


Comments and discussion about How to output (echo/print) content in PHP

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the PHP language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

What are route patterns in Laravel?

PHP Date commonly used formats

How to install and use optipng on Linux CentOS

How to block IPv6 IP addresses in .htaccess

How to select what columns to return when calling ::all()

What is the difference between reference and primitive data types types in Javascript?

How to namespace a Laravel route group?

How to show (or log) all SQL queries executed by Laravel

How to check if a string contains a certain substring?

How to increment a value in the database