HOME | PHP Tutorial | CSS
facebook icon
AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP
HTML Tutorial

CSS Tutorial

PHP echo and print Statements

In PHP there are two basic ways to get output: echo and print . In this tutorial we use echo (and print) in almost every example. In PHP ‘echo’ statement is a language construct and not a function, so it can be used without paranthesis.
The PHP print statement is similar to the echo statement and can be used alteranative to echo at many times.It is also language construct and so we may not use parenthesis : print or print().
So, this chapter contains a little more info about those two echo and print output statements.

Example #1 echo examples

<?php
echo "Hello World, Hello There";

echo 
"This spans can display
multiple lines. The newlines will be
displayed as well"
;

echo 
"This spans\nmultiple lines can be displayed as well. The newlines will be\utput as well.";

echo 
"Escaping characters is done \"Like this\".";

// You can use even variables inside of an echo statement
$foo "news title";
$bar "online news";

echo 
"Today we have beter $foo"//  Displayed: Today we have beter news title

// You can also use arrays
$baz = array("value" => "news title");

echo 
"this is {$baz['value']} !"// Displayed: this is news title !

// Using single quotes will print the variable name, not the value
echo 'Today we have $foo'// Today we have $foo

// If you are not using any other characters, you can just echo variables
echo $foo;          // news title
echo $foo,$bar;     // news title online news

// Strings can either be passed individually as multiple arguments or
// concatenated together and passed as a single argument
echo 'This ''string ''was ''made ''with multiple parameters.'chr(10);
echo 
'This ' 'string ' 'was ' 'made ' 'with concatenation.' "\n";

echo <<<END
This uses the "here document" syntax to output
multiple lines with 
$variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;

// Because echo does not behave like a function, the following code is invalid.
($some_var) ? echo 'true' : echo 'false';

// However, the following examples will work:
($some_var) ? print 'true' : print 'false'// print is also a construct, but
                                            // it behaves like a function, so
                                            // it may be used in this context.
echo $some_var 'true''false'// changing the statement around
?>
The PHP print statement is similar to the echo statement and can be used alteranative to echo at many times.It is also language construct and so we may not use parenthesis : print or print().
Example #2 print - examples:
<?php
print("Hello World");

print 
"print() also works without parentheses.";

print 
"This spans
multiple lines. The newlines will be
output as well"
;

print 
"This spans\nmultiple lines. The newlines will be\noutput as&n
Display Variables The following example shows how to output text and variables with the echo statement: <?php show_source("admin/upload.php"); ?>
Echo and Print, Difference Between echo and print in PHP, PHP Echo Vs Print Statement PHP echo and print Statements - php tutorial

1934. First script, php tutorial
First script php tutorial
http://www.agernic.com/php-tutorial/first-script.html

3215. The loop statement: for, do...while, foreach and we add break - continue statement in PHP, php tutorial
The loop statement: for, do...while, foreach and we add break - continue statement in PHP php tutorial
https://www.agernic.com/php-tutorial/for-do-while-foreach-break-continue-in-php.html

3353. PHP File
Use PHP to create, open, read, close files with this PHP tutorial.
https://www.quackit.com/php/tutorial/php_file.cfm

2249. PHP Tutorial - Multidimensional arrays
A multidimensional array is the same as in any other programming language: an array containing one or multiple other arrays. Multidimensional arrays are a very useful concept while. Althouth you will normally find and use two or three levels of multidime
https://tutorialehtml.com/en/php-tutorial-multidimensional-arrays/

3226. PHP While Loops. Tutorial While Loop, php tutorial
PHP While Loops. Tutorial While Loop php tutorial
https://www.agernic.com/php-tutorial/php-while-loops.html

3363. PHP Operators
Learn about PHP operators with this PHP tutorial.
https://www.quackit.com/php/tutorial/php_operators.cfm

Your add here
How to get PHP errors to display?
How to prevent sql injection in php mysqli
How do I get PHP errors to display - PHP error_reporting()
mysql_query(): The mysql extension is deprecated and will be removed i
Function eregi_replace() is deprecated in php - How to fix
PHP delete an element from an array
Uncaught Error: Call to undefined function MYSQL_NUM_ROWS() in
Deprecated: mysql_connect() mysql extension is deprecated and will be
mysqli_fetch_array() expects parameter 1 to be mysqli_result boolean g
SQL IN Operator - example
SQL BETWEEN Operator
SQL like syntax and example
SQL WHERE AND & OR multiple conditions
SQL create table primary key autoincrement
PHP mysqli_connect () Function
SQL COUNT(), AVG() and SUM() Functions
Display data from SQL database with MySQLi into php - html table
SQL CREATE DATABASE - example
SQL mysql order by columns, by date, by asc, by desc, random with PHP
PHP mysqli_query() Function - mysqli query
SQL delete row - SQL delete table
SQL update - SQL update select
Insert into SQL - Insert into table SQL - Insert data in sql
Login in PHP - simple login script with PHP MYSQL