In PHP, a string is simply a group of characters.
They can contain:-
When you assign a string to a variable (or) echo the string out to the browser, you have to mark the start and end of the string.
The ways of doing this are:
The two methods looks similar but they are slightly different. Look at the following codes:-
<html> <head><title>quotes</title></head><body>
<?php $name = "Sally"; echo "My name is $name"; echo "<br>"; echo 'My name is $name'; ?> </body> </html>
You will see that the output of above are different.
In the first code line, a variable was put between a pair of double quote. Its value Sally was displayed by the browser echo "My name is $name"; => My name is Sally
In the next code line, a variable was put between a pair of single quote. Its value Sally was not displayed by the browser. echo 'My name is $name'; => My name is $name
Play around with single and double quotes with different strings and variables and observe the differences.
စာလံုး အကၡရာ အတြဲလိုက္ အစုအေဝး မ်ား ကို PHP တြင္ string ဟု ေခၚပါ သည္။Strings မ်ားတြငိ ေအာက္ပါ တို႔ ပါဝင္ ပါသည္။
စာလံုး အကၡရာ အတြဲ (strings) မ်ား ကို variable တြင္ assign လုပ္ သည့္ အခါ (သို႔မဟုတ္) စာလံုး အကၡရာ အတြဲ (strings) မ်ား ကို echo သံုး၍ computer screen ေပၚတြင္ ပံုေဖၚ သည့္ အခါ တြင္ ေသၚ ၄င္း string ၏ အစ (start) ႏွင့္ အဆံုး (end) တို႔ကို မွတ္သား ေပး ရသည္။.
၄င္း အမွတ္ အသားကို single quote ( ' ) သို႔မဟုတ္ double quote ( " ) အသံုးျပဳ ေဆာင္ရြက္ သည္။
အထက္ ပါ နည္းလမ္း ၂ ရပ္မွာ တူသေရာင္ ရွိ ေသၚလည္း လုပ္ေဆာင္ ပံု အ နည္းငယ္ ကြဲျပား ပါသည္။
အထက္ ေဖၚျပ ပါ PHP code သည္ ေအာက္ ေဖၚျပ ပါ အတိုင္း screen ေပၚတြင္ လါေပၚ ပါမည္။ နည္းလမ္း ၂ ရပ္ လုပ္ေဆာင္ ပံု မတူ သည္ကို ေသခ်ာစြာ ေလ့လာ ပါ။
ပထမ code လိုင္းတြင္ variable ကို double quote ႏွစ္ခု အၾကား တြင္ ထား ပါသည္။ Screen တြင္ Sally ဟူေသာ စာစု လာေပၚ ပါမည္။ echo "My name is $name"; => My name is Sally
ဒုတိယ code လိုင္းတြင္ variable ကို single quote ႏွစ္ခု အၾကား တြင္ ထား ပါသည္။ Screen တြင္ Sally ဟူေသာ စာစု မေပၚပဲ $name ဟု လာေပၚ ပါမည္။ echo 'My name is $name'; => My name is $name
Single quote ႏွင့္ double quote ကို သံုးၿပီး string မ်ား ကို အမ်ိဳးမ်ိဳး ကစား ၾကည့္ ပါက ပိုမို နားလည္ လာပါ လိမ့္မည္။