Home Logo
Show Full Menu
Hide Full Menu
 

Print and Echo

Created: 30/09/10 Views: 841 myFave Image


In this tutorial we will learn the print and echo commands
To start this PHP series off we are going to look at 2 very simple and useful commands which are print and echo. These to commands display a string into your web page, and through these examples it may seem pretty pointless, but at the moment all you need to know is how to use them.
Both these commands do pretty much the same thing, and so it causes a lot of discussions on which one is best to use, it has been suggested and I think proven that echo is the fastest to process how ever just use which ever takes your liking the most it hardly matters, I personally use print and I have no idea why, after all echo does sound much cooler.

Here are examples of print and echo, make sure you try this out for yourself!
    Script
  • <?php
  • print "Hello Dude!!";
  • ?>

    Result
  • Hello Dude!!

    Script
  • <?php
  • echo "Hello Dude!!";
  • ?>

    Result
  • Hello Dude!!


    Script
  • <?php
  • print "Hello <br/>";
  • print "Dude!!";
  • ?>

    Result
  • Hello
  • Dude!!

    Script
  • <?php
  • echo "Hello <br/>";
  • echo "Dude!!";
  • ?>

    Result
  • Hello
  • Dude!!

It's nothing spectacular I know, but if you can't grasp something this simple, perhaps PHP isn't for you, if you've nailed it then good, because we are going to be using this plenty of times.

Just as a side note before we move on, with print and echo, you are able to use both single quotations, ' , and double quotations, " , however there is a difference, when using variables, if you use single quotations and include the variable, it will print/echo the variable's name rather than its value.


next tutorial: Variables

There are no comments