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

PHP echo and print Statements


<< Previous Page
PHP Variables
Next Page >>
PHP Data Types
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().

Difference between print and echo.
"Print" prints a single string, "echo" can print multiple strings separated by a comma.
So, this chapter contains a little more info about those two echo and print output statements.

Example:
print 'Hello world!';
echo 'Hello world!', 'again we can say - Hello world!';


Example:
<?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
<?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");
?>


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


Echo and Print, Difference Between echo and print in PHP, PHP Echo Vs Print Statement
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.