PHP Introduction to PHP Echo and print Tutorial
Posted on: April 14, 2006 at 12:00 AM
Do you know the difference between the common echo() and print() functions? Also you will find here a basic description of variable functions in PHP.
Ok, this is a basic tutorial to help people just getting started with PHP. In this tutorial I will show you how to output to the webpage. We will use two forms of outputting: print() and echo().

First things first: all newcomers to PHP will be happy to know that PHP code can be written or added directly to your HTML!! All you have to do is put it between the <?php and ?> tags.

          php stuff

Ok, now that said, let's go to what this tutorial was written for.
The first outputting function I will show you is print().
This is very easy to use, and in fact, the parentheses are not even necessary. The basic structure of print() is:

          print("This is outputted to the webpage");
          print "so is this!";

You can also declare variables and then output them using the print function:

          $hello = "hello"
          print("$hello");     //this print the hello variable
          print "$hello";

That's really all there is to it. One thing is that it cannot be used in a variable function, which I'll explain in a few minutes.

The next method of outputting to a webpage is the echo() function. It is used the same way as print().

          $kool = "this is kool";
          echo ("$kool prints \"kool\"");
          echo "this does too!";
          echo "this prints \"hello\" too!";

What's the difference between the two ? Well, one difference is that echo() can take multiple expressions:

          echo "The first", "the second";

Print cannot take multiple expressions. That is the main distinct difference!

So there, you now have 2 ways of outputting text or variables to the webpage, but what about that variable function you ask ? Well, variables functions are things that don't work with echo() and print(). It basically means that if you were to put the name of a function inside a statement, it would try to execute the function.
It is a very confusing concept, even for me, so visit the php manual on variable funtions for more info. Here is some example code that may help you understand variable functions:

<?php function foo()
    echo "In foo()\n";

function bar($arg = '')
    echo "In bar(); argument was '$arg'.\n";

$func = 'foo';
$func = 'bar';

In the code above there are two simple functions are declared. Then their names are assigned to the variable and both functions are executed using this variable. More Tutorials on for the topic PHP Introduction to PHP Echo and print Tutorial.
PHP Introduction to PHP Echo and print Tutorial
Ok, this is a basic tutorial to help people just getting started with PHP... forms of outputting: print() and echo(). First.... The basic structure of print() is:      <?php  
What is the use of Print or Echo Function in PHP?
What is the use of Print or Echo Function in PHP?  Hi, Can anyone explain what is the use of print or Echo function in PHP? Please provide online... or Echo Function in PHP are same. But on comparing we can say that echo function
Print or Echo Functions in PHP
Print or Echo Function in PHP Although the use of both Print and Echo are same, but it has been seen that people uses echo command more then the print... time to process. Lets take an example of print and echo command: <?php print
echo- Not a function
echo- Not a function       In php generally we use echo command to print something. echo is not a function...: This is multiple line Example: <?php echo "Hello world"."<br/>"
javascript echo php
javascript echo php  i would like to know the complete syntax with the running example of using JavaScript echo in PHP. Thanks
Sitemap PHP Tutorial
Questions | Site Map | Business Software Services India PHP Tutorial... by PHP  | PHP Ajax | PHP SimpleXML | PHP Ajax DB PHP Tutorial Section... Learn PHP | What a PHP Programmer Can Do PHP Beginner Tutorial Section - II
Introduction to PHP Array
What is Array? An array in PHP is actually an ordered map, what is a map...;value) An example of an array is given below: <?php $first=array('Name' =>'Rose', 18=>"true"); echo $first['Name']."<br/>
HelloWorld in PHP
extension (e.g. HelloWorld.php)  Inside the file write: <?php echo 'Hello... $a [,string ... ]) echo does not  return any value. Another way to print...Hello World in PHP Program To write and run your first PHP program, open
PHP Getting Started With PHP Tutorial
learning php!" using PHP, then either use print or echo command, both are used...; print("I am learning PHP"); ?> Example 2: <?php   echo... on the screen : I am learning PHP  print and echo are almost similar
PHP Basics, PHP Basics tutorials for beginners
construct.   Introduction to PHP array: This tutorial gives you...PHP Basics - Basics Tutorials for the beginners Introduction to PHP... way to teach PHP scripting language. In our Online Free PHP tutorial we have
PHP Echo Function
PHP Echo Function As you know echo () is one of the function of php, which... the echo function as given below… <php Echo “hi how are you... to it. And just write “echo $variablename; PHP Echo Function Example: <php
PHP AJAX Introduction
PHP-AJAX-Introduction In this current tutorial we will study how to integrate a simple PHP file with AJAX, how to put some AJAX affect in a PHP file... will need three different files html file, JavaScript file, and PHP file. php
PHP String Function
print these all. PHP String Function Example: <?php $a="...PHP String Function: A string is nothing but a series of characters. Most... want to print backslash. In the following example we will also learn about
What is PHP ?
What is PHP? PHP is an acronym stand for Hypertext PreProcessor. It is an open... in HTML. PHP is free, efficient, and that's why it is very popular in web development scenario. PHP coding is enclosed within <?php   ?> tag
PHP Tutorial
PHP Tutorial  Hi, I am new in PHP programming. Can anyone provide me good urls to learn PHP? Thanks   Hi, Start learning PHP at PHP Tutorial section. Thanks
PHP Tutorial
PHP Tutorial  Hi, I am looking for PHP tutorials on Provide me the urls of PHP tutorials? Thanks   Hi, Here is the links on PHP Tutorial Complete PHP Tutorials Many Free PHP Tutorials
current date in php
, You can use the following code to print the current in PHP: <?php echo...;?=$today?> More tutorial on PHP date are available at: and
PHP Variable
PHP Variables, Special Symbols in PHP In any language variables are one of the most important thing, in PHP we can declare a variable of any type, any where.  PHP Variable Example 1: <?php $var="
PHP Echo Variables
PHP Variables Echo PHP Echo() Function is used to display the output of your... outputs can be through only one echo() command. For example : <?php... echo. If you want to passed more than one variable to display then it shouldn't
echo and print statement
echo and print statement  hello, What is the difference between echo and print statement?   hii, echo() can take multiple expressions, Print() cannot take multiple expressions. And echo is a little bit faster
echo and print statement
echo and print statement  hello, What is the difference between echo and print statement
", and i use if condition for each value and display by using "echo" but it difficult... shortcut method in php like in javscript seletedIndex
PHP toString Function
of the object, if we try to print the object, __toString() function is called implicitly and print the value of the member variable. PHP toString Function...__toString method in PHP: In the previous versions of PHP it is not possible
PHP Variables Types
an object. Example: <?php $a=33; $ref=&$a; echo "Value...PHP Variables: In PHP a variable is declared with a dollar sign followed... variable, the data type of the variable changes to that only. It means in PHP
PHP Introduction to PHP Include and require Tutorial, PHP include and require
PHP include and require In this tutorial we will learn how to use PHP include.... In PHP there are two very similar functions to include files: include() ... when file does not exist in specified path. If file to include has PHP script
The Tutorial illustrate an example from PHP SQL Fetch. To understand and grasp... PHP SQL Fetch       PHP SQL Fetch is used to fetch the records from Mysql database to PHP
MySQL PHP Insert
queries in the PHP server side script and print the records on the browser. Understand with Example The Tutorial illustrate an example on MySQL PHP Insert... MySQL PHP Insert      
Strings in PHP
in PHP and different ways to print a string. Can someone help me in this regards?   Following tutorials will help you in details about strings in PHP...:// Thanks
php Basic Syntax
php Basic Syntax       In the given tutorial we will study how to write the basic syntax of php: <?php ?>... has to be written within this tag. <?php echo "Hello World"; ?>
PHP PHP Triad Tutorial
PHP-Triad Tutorial       In this PHPTriad tutorial we will learn how to download install and test an application...\HTDOCS folder type the following code and save it as Hello.php. <?php echo
Mysql PHP Where
Mysql PHP Where       Mysql PHP Where is used to insert the records from database and print... The Tutorial illustrate an example from 'Mysql PHP Where'. To understand and grasp
Php Array Multidimensional
;<br>";     print_r($nature[0]);     echo...; print_r($nature[1]);     echo "<br><u>array22... Multidimensional array can be two dimensional or multidimensional array PHP
php  im beginner to php. i faced problem with creating form and data stored into mysql <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01... executes if($result){ echo("<br>Input data is succeed"); } else{ echo
php  im beginner to php. i faced problem with creating form and data stored into mysql <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01... executes if($result){ echo("<br>Input data is succeed"); } else{ echo
PHP Variable Functions
to execute it. This variable function does not work with echo(), print(), unset...PHP Variable Functions: Learn PHP Variable Function means that if a variable name has a format like this $var(), PHP will consider this as a variable function
PHP SQL Select Where
' from table 'user'. The echo , property of PHP is used to print the records... PHP SQL Select Where       PHP SQL Select Where is used to provide the records from the table
PHP Array
is used to print the elements of an array"; echo "<br/>Another...) } Example 4: <?php echo "This is an example of numeric...:    
PHP array length for, PHP array length for loop
In this tutorial we will iterate PHP array using the for loop. We will find the length of the array and then print all the values in it. The following... the same: <?php $counter=0; while( $counter< $count){ echo
PHP Sorting Arrays Tutorial
;; echo "<b>After sorting values become:</b>"; print_r... rover"); echo "<b>Before sorting the values are:</b>"; print...;; print_r($car); arsort($car); echo"<br/>"; echo "<b>
PHP MySQL Introduction
PHP/MYSQL INTRODUCTION TUTORIAL Part - 1 : Introduction  The combination... Database Management  System. In this tutorial, we will learn how to use PHP... our PHP tutorial.  
How to Append Arrays in PHP
_merge(), + operator etc. This free php tutorial has small description of print_r...How to append array or merge two arrays in PHP: This PHP tutorial is discussed... of example 4 as mentioned below:   <?php echo "<b>
Complete php tutorial
Learn PHP at PHP - Hypertext Preprocessor tutorial page. Thanks...Complete php tutorial  Hi, I am trying to find the url to learn complete PHP in easily. Can some one provide me url for complete php tutorials
PHP Introduction
The quick introduction to the PHP programming language PHP is server... for their website. The PHP stands for PHP: Hypertext Preprocessor. The php program is simple text file with the .php or .php5  extensions. You can use
Best PHP tutorial for beginners
Best PHP tutorial for beginners  Hi Friends, I want to learn PHP... Tutorial index page. You find good tutorials for learning php from beginning. Installing PHP Installing PHP LAMP PHP MySQL Tutorial index page. Above tutorials
PHP Date function
a"); echo ("<br>");   /*We can print any message...PHP Date Function In this section we will show you the different formatting options available in the PHP Date function PHP date() function provides many
PHP Array
PHP Array In this page we will learn about PHP Array. We will also understand how to use PHP Array in your PHP program. The PHP Array is very useful in developing PHP based applications. PHP Arrays are ordered map which is used
PHP Form, PHP guest form
;); The whole PHP code from the first part of the tutorial will look like...PHP email form HTML form It's not a good idea to leave your private e... of this tutorial I'll tell you in details how to create a mailbox
ppt php tutorial
ppt php tutorial  How can i work with ppt files in PHP
Example of fgetc in PHP, fgetc php, fgetc in php
Learn how to use the fgetc() function in PHP programming. Syntax string...; If <Br> is used then result will be one character in single line Code for PHP fgetc() Function <?php $file1=fopen("c:/rose1/ram.txt"
PHP Array Prepend
PHP Array Prepend In this PHP Array tutorial we will come to know about how... will be modified to  zero. Example 1: <?php $array=array("diwali","dushera","chirstmas"); echo("<b>

Related Tags for PHP Introduction to PHP Echo and print Tutorial: