Home
Recent Articles
Php (By Category)
Misc (1)
News (1)
String (1)
Resources (By Category)
Web (2)
Tutorials
Using The Function Echo
Show Myanmar Version show-myanmar-fontPrinter Friendly Page

Using the function 'echo'
By - Ko Ko - December 28, 2006 - 10:18 am

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


(End of Article)

url = http://PhpMyanmar.com/pphp/article/169
Get results from [ 18 ] search engines in 'one click'
 
Install Myanmar Font
  • Download the font, (zawgyi-one) here.
  • See how to install the font here.
Feedback (In English please)
Bigger-Shoutbox
 
visited