Home
Recent Articles
more...    [all articles]
Articles by Catagory
php (12 )
css (1 )
Tutorials
Related Links
Using The Function Echo
Posted By - Ko Ko - December 28, 2006

Summary :
How to use the function echo
Printer Friendly Page
Show Myanmar Version show-myanmar-font

Using the function 'echo'

No matter how complicated a program is, finally it will return an answer.

Then the programmer usually do the followings-

  • Save the answer to a file.
  • Put it on the monitor screen for the user to see.
  • Output it to a speaker or earphone for the user to hear.

Let us confine yourself to putting something on the screen for the user to see.

PHP use the function echo to make users see things on the screen.

There are several other functions either than echo but we will study only echo here.

The easiest way to understand something is to study a working example

Copy and paste the following codes to a notepad and save it as a file name echo_example.php in the easyphp 'www' folder.

code.1
<html>
<head>
<title>Using echo function</title>
</head>
</body>

<?php
error_reporting(E_WARNING); //just put above line , don't ask anything //concentrate on usage of echo
echo "Hello World "; echo "<br>=========================<br>";
echo "This spans multiple lines. The new lines will be output as well"; echo "<br>=========================<br>";
echo "Escaping characters is "Like this".";
echo "<br>=========================<br>";
$foo = "foobar"; $bar = "barbaz"; echo "foo is $foo";//foo is foobar echo "<br>"; echo "bar is $bar";//bar is barbaz echo "<br>=========================<br>";
// You can also use arrays $bar1 = array("value" => "foo"); echo "this is {$bar1['value']} !"; // this is foo ; echo "<br>=========================<br>";
// Using single quotes will // print the variable name, // not the value echo 'foo is $foo'; // foo is $foo echo "<br>=========================<br>";
// If you are not using any // other characters, you can // just echo variables
echo $foo; // foobar echo "<br>"; echo $foo.$bar; // foobarbarbaz echo "<br>=========================<br>";
// Some people prefer passing // multiple parameters // over concatenation. //with multiple parameters> echo 'This ','string ','was ','made.'; echo "<br>"; //with concatenation echo 'This '.'string '.'was '.'made.'; echo "<br>=========================<br>";
$foo = <<<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 white space!
END;
echo $foo;
echo "<br>=========================<br>";
?>
</body> </html>

Open a browser and type - http://localhost/echo_example.php - in the address bar and you will see as in figure.1

figure.1

Study 'code.1' line by line and compare with the result of the monitor screen.

When you see a bunch of codes that is working properly. hold on to it. Save it somewhere. Then make a copy and play around with the code and see what happened.

Don't try and change in a lot of places at once otherwise you won't know where you go wrong. See what type of error message PHP post back to you.

This is the best way to learn by yourself and it was and still is the way I learn PHP.

Download echo_example.zip

Posted as - [programming] [php] [code snippets]

End of Article - Using the function echo
http://phpmyanmar.com/content/article//using-the-function-echo.html

1 comment

kiruJuly 7, 2010 - 4:34 am
Coolz..example..for beginner..thanks and keep on sharing..thz..much..

Leave your comment

Name

You can type in both English and Myanmar (Use Zawgyi Font)

<< Type above word in this box

Install Myanmar Font
  • Download the font, (zawgyi-one) here.
  • See how to install the font here.
PhpMyanmar Forum
Feedback (In Eng and Myan)