PHP Echo and Print Statements
PHP Tutorial » PHP Echo and Print Statements
What does PHP echo do?
"echo" statement display anything that can be displayed in the browser, such as string, numbers, variable values, expression results, and so on.
PHP echo is a language construct, not a function.
"echo" is a language construct, but it is not a function as "if" statement and can use it without parentheses as:. echo or echo()
Syntax:
// Displaying string of text
echo "any text here";
?>
The output of the above PHP code it is the text between quotes without quotes
PHP print statement
You can use the "print" statement as an alternative to echo to display the result in your browser. Like echo, print is also a construction of language and not a function. So print or print () can be used without parentheses , but also with parentheses.
Both the echo statement and the print statement work in exactly the same way, except that the print statement can only draw one string and always returns 1. Therefore, the echo statement is considered faster than the print statement because it returns no value.
Syntax:
// Displaying string of text
print "any text here";
?>
The output of the above PHP code it is the text between quotes without quotes
PHP echo Display HTML Code
The following example will show you how to display HTML code using "echo" statement:
<?php
// Displaying HTML code
echo "<h2>This is a heading for your text.</h2>";
echo "<h3 style='color: green;'>This is heading with inline-css-style.</h3>";
?>
Display Strings of Text using print statement
The next example will show you how to display a string of text with the print statement:
<?php
// Displaying string of text
print "Hello World!";
?>
Related subjects:
PHP syntax
What is an array
PHP variabl
Array to comma separated
Tags: php echo new line, echo vs print, array, variable, date, html code, multiple lines, hello world, array values, json, line break, not working
What does PHP echo do?
Does ECHO work in PHP?
What does echo stand for in PHP?
What is the output of PHP echo I am a PHP script?
php print_r, array, to console, printf, new line, object, date, vs echo, date, array to file, stack trace, page, array as string,
What is PHP print?
What does Print_r mean in PHP?
What is echo in PHP with example?
How does echo work in PHP?
Display Variables using echo statement
The next example will show you how to display variable in PHP using the echo statement:
<?php
// Defining variables
$my_txt = "Hello World!";
$my_num = 34865;
$my_colors = array("green", "blue", "red");
// Displaying variables
echo $my_txt;
echo "<br>";
echo $my_num;
echo "<br>";
echo $my_colors[0];
?>
To see the result of the PHP code above please click Execute
PHP variables and array as string using print
The next example will show you how to display variable in PHP using the echo statement:
<?php
// Defining variables
$my_txt = "Hello World!";
$my_num = 34865;
$my_colors = array("green", "blue", "red");
// Displaying variables
print $my_txt;
print "<br>";
print $my_num;
print "<br>";
print $my_colors[0];
?>
php echo new line, echo vs print, array, variable, date, html code, multiple lines, hello world, array values, json, line break, not working
What does PHP echo do?
Does ECHO work in PHP?
What does echo stand for in PHP?
What is the output of PHP echo I am a PHP script?
php print_r, array, to console, printf, new line, object, date, vs echo, date, array to file, stack trace, page, array as string,
What is PHP print?
What does Print_r mean in PHP?
What is echo in PHP with example?
How does echo work in PHP?
PHP echo and print Statements - php tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.