PHP echo and print Statements

Posted on

tyryPHP echo and print Statements

In PHP we use two basic ways to print output on screen: echo and print. Double quotes use for string or line display on screen and for variable we write normally not with quotes. The syntax of the echo and print is:

Echo “here I can write the content”;

PHP echo and print Statements both are same. They both  are used to output data to the screen.

The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. Echo is faster than Print Statement.

The PHP echo Statement

We can use echo statement with or without parentheses: echo or echo().

Display Text

This example show the concept of echo command

Example

<?php
echo “<h2>PHP is Fun!</h2>”;
echo “Hello world!<br>”;
echo “I’m about to learn PHP!<br>”;
echo “This “, “string “, “was “, “made “, “with multiple parameters.”;
?>

Display Variables

This example show how to output text and variables with the echo statement:

Example

<?php
$txt1 = “Learn PHP”;
$txt2 = “technocampus.com”;
$x = 5;
$y = 4;

echo “<h2>$txt1</h2>”;
echo “Study PHP at $txt2<br>”;
echo $x + $y;
?>

The PHP print Statement

We can use the print statement with or without parentheses: print or print().

Display Text

This example shows how we can use print command.

(notice that the text can contain HTML markup):

Example

<?php
print “<h2>PHP is Fun!</h2>”;
print “Hello world!<br>”;
print “I’m about to learn PHP!”;
?>

Display Variables

This example shows how to output text and variables work together  with the print statement:

Example

<?php
$txt1 = “Learn PHP”;
$txt2 = “technocampus.com”;
$x = 5;
$y = 4;

print “<h2>$txt1</h2>”;
print “Study PHP at $txt2<br>”;
print $x + $y;
?>

For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.

Helpline: 9814666333, 8699444666

Email:info@technocampus.co.in

**************************************************************************************************************

Please fill the FORM and we shall contact you soon.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s