YouTip LogoYouTip

Php Echo Print

PHP 5 echo/print Statements |

-- Learning More Than Just Technology, But Also Dreams!

PHP Tutorial

PHP Forms

PHP Advanced

PHP 7 New Features

PHP Database

PHP XML

PHP and AJAX

PHP Reference

PHP Variables

PHP EOF(heredoc) Usage

Explore Further

  • Scripting Languages
  • Computer Science
  • Web Services
  • Software
  • Web Design & Development
  • Programming Languages
  • Programming
  • Web Service
  • Development Tools
  • Scripting

PHP 5 echo and print Statements


In PHP, there are two basic output methods: echo and print.

In this chapter, we will discuss the usage of these two statements in detail and demonstrate how to use echo and print with examples.


PHP echo and print Statements

Differences between echo and print:

  • echo - Can output one or more strings
  • print - Can only output one string, and its return value is always 1

Tip: echo is faster than print. echo has no return value, while print has a return value of 1.


PHP echo Statement

echo is a language construct, so you can use it with or without parentheses: echo or echo().

Displaying Strings

The following example demonstrates how to use the echo command to output a string (the string can contain HTML tags):

Example

<?php
echo "<h2>PHP is fun!</h2>";
echo "Hello world!<br>";
echo "I want to learn PHP!<br>";
echo "This is a string, using multiple parameters.";
?>

Try it Β»

Displaying Variables

The following example demonstrates how to use the echo command to output variables and strings:

Example

<?php
$txt1 = "Learning PHP";
$txt2 = ".COM";
$cars = array("Volvo", "BMW", "Toyota");

echo $txt1;
echo "<br>";
echo "Learning PHP at $txt2";
echo "<br>";
echo "My car brand is {$cars}";
?>

Try it Β»


PHP print Statement

print is also a language construct, and you can use parentheses or not: print or print().

Displaying Strings

The following example demonstrates how to use the print command to output a string (the string can contain HTML tags):

Example

<?php
print "<h2>PHP is fun!</h2>";
print "Hello world!<br>";
print "I want to learn PHP!";
?>

Try it Β»

Displaying Variables

The following example demonstrates how to use the print command to output variables and strings:

Example

<?php
$txt1 = "Learning PHP";
$txt2 = ".COM";
$cars = array("Volvo", "BMW", "Toyota");

print $txt1;
print "<br>";
print "Learning PHP at $txt2";
print "<br>";
print "My car brand is {$cars}";
?>

Try it Β»

← Php DatatypesNode Js Get Post β†’