AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

PHP Echo and Print Statements


<< Previous Page
PHP Variables
Next Page >>
PHP Data Types

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:

<?php
// 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:

<?php
// Displaying string of text
print "any text here";
?>

The output of the above PHP code it is the text between quotes without quotes

Note: "echo" statement considered faster than the "print" statement.

 

PHP echo Display HTML Code

The following example will show you how to display HTML code using "echo" statement:

Example (this is HTML - PHP editor, change text, values on this window)
<?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:

Example (this is HTML - PHP editor, change text, values on this window)
<?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:

Example (this is HTML - PHP editor, change text on this window)
<?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:

Example (this is HTML - PHP editor, change text on this window)
<?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

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Error: Unable to connect to MySQL. Debugging errno: 1045 Debugging error: Access denied for user 'u142985959_ager'@'localhost' (using password: YES)