Using the function 'echo'
By - Ko Ko - December 28, 2006 - 4:18 am
ပရိုဂရမ္ တခုကို run လုပ္တဲ့ အခါ
ဘယ္ေလာက္ ပဲ ရွုပ္ေထြး တဲ့
ပရိုဂရမ္ ျဖစ္ေန ပါေစ၊ ေနာက္ဆံုး မွာ ရလာဘ္
အေျဖ တခု ကို return ျပန္ ပို႔ေပး မွာ
ျဖစ္ ပါတယ္။
ဒီအခါ မွာ programmer ဟာ ေအာက္ေဖၚျပ ပါ လုပ္ေဆာင္ ခ်က္ တခုခု ကို အမ်ား အားျဖင့္
ေဆာင္ရြက္ မွာျဖစ္ ပါတယ္။
- ျပန္ရတဲ့ return ကို file အခု အေနနဲ႔ save လုပ္ျခင္း
- ကြန္ပ်ဴတာ monitor screen ေပၚမွာ user ေတြ ျမင္ရေအာင္ ေရးျပျခင္း
- User ေတြ ၾကားႏိုင္ ေအာင္ speaker သို႔မဟုတ္ earphone သို႔ အသံအျဖစ္ output
လုပ္ေပး ျခင္း။
ေလာေလာဆည္ ေတာ့ monitor screen ေပၚမွာ user ေတြျမင္ ရေအာင္ ေရးျပ တဲ့
လုပ္ငန္း ကိုပဲ ေလ့လာၾက ရေအာင္း.
PHP ဟာ echo ဆိုတဲ့
function ကိုသံုး ၿပီး users ျမင္ရ ေအာင္ monitor screen ေပၚ မွာ ေရး
ပါတယ္။
echo အျပင္ screen ေပၚမွာ ေရးခိုင္း
ႏိုင္တဲ့ အျခား function ေတြ ရွိေန ေပမဲ့ ဒီမွာေတာ့ echo
တခုထဲ ကို ပဲ ေလ့လာ သြားမွာ ျဖစ္ ပါတယ္။
အလြယ္ဆံုး နည္းလမ္း ကေတာ့ အမွားမရွိ ပဲ run လုပ္ႏိုင္တဲ့ working example တခု
ကို ေလ့လာ ျခင္း ပါဘဲ။
ေအာက္မွာ ေဖၚျပ ထားတဲ့ code ကို copy လုပ္ၿပီး notepad တခု မွာ paste လုပ္ပါ။
ၿပီးရင္ echo_example.php ဆိုတဲ့ file name နဲ႔ 'www' folder မွာ save လုပ္ပါ။.

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>
ၿပီးရင္ browser တခု ကို ဖြင့္ၿပီး address bar မွာ
http://localhost/echo_example.php လို႔ ရိုက္ ထည့္ၿပီး enter ကို ႏွိပ္ ပါက figure.1
မွာ အတိုင္း ျမင္ရ ပါ လိမ့္မယ္။
figure.1

'code.1' ကို တလိုင္း ခ်င္း ေစ့ေစ့ စပ္စပ္
monitor screen ေပၚ မွာ ေတြ႔ ရတာနဲ႔ တိုက္ ဆိုင္ ေလ့လာ ပါ။.
PHP ကို ေလ့လာ ရာမွာ ကၽြန္ေတာ္ နည္းလမ္း တခု ကို ေဖၚျပ ပါမယ္။
အမွား အယြင္း မရွိ run လုပ္ႏိုင္တဲ့ PHP file တခုကို ရရွိတဲ့ အခါ ပထမ ဆံုး
တေနရာရာ မွာ copy တခုကို
ေနာင္ လိုအပ္ ရင္ ပြားယူ လို႔ ရေအာင္ save လုပ္ ထားပါ။ ၿပီရင္ PHP codes
ေတြကို ဖ်က္ၿပီး အမ်ိဳးမ်ိဳး run လုပ္ ၾကည့္ပါ။
အမွား ကို တမင္တကာ လုပ္ ၾကည့္ တဲ့အခါ ေနရာ ေပါင္းစံု မွာ
တၿပိဳင္နက္ လုပ္ရင္ အေျဖ ရွာရ ခက္
ပါတယ္။ တေနရာ မွာ အမွား လုပ္ၾကည့္ လိုက္၊ ဘာျဖစ္ လာသလဲ ေလ့လာ။ မွန္ ေအာင္ ျပန္လုပ္
လိုက္္၊
ဆိုတဲ့ နည္းလမ္း ကို သံုးရင္ မၾကာမွီ ကၽြမ္းက်င္ လာပါ လိမ့္ မယ္။
ဒီနည္း ဟာ အရင္ ကေရာ ယခု လက္ရွိပါ ကၽြန္ေတာ္ သံုး ေနတဲ့ self learning နည္းလမ္း
ျဖစ္ ပါတယ္။