Program 1:
// Simple string
echo
’I am a geek. ’
;
echo
""
;
// use a backslash to display a line with an apostrophe
echo
’It’ll be interesting to know about the string. ’
;
echo
""
;
// escape backslash in line
echo
’A is named as backslash. ’
;
echo
""
;
// Variable will not be evaluated if used directly
// inside a string in single quotes
$string
=
’ engineer’
;
echo
’This is a portal for $string. ’
;
echo
""
;
// / n will be displayed unchanged
// special meaning.
echo
’This is a portal for engineer. ’
;
?>
Output:I am a geek. It’ll be interesting to know about the string. A is named as backslash. This is a portal for $string. This is a portal for engineer.
Double quoted strings:double quoted strings cause PHP code to evaluate the entire string. The main difference between double quotes and single quotes is that with double quotes, you can include variables directly in the string. It interprets Escape sequences. Each variable will be replaced with its own value.The program below illustrates lineswithin double quotes:
Program 2:
// Simple string.
echo
"I am a geek . "
;
echo
" "
;
// Nothing extra here
echo
"It’ll be interesting to know about the string."
;
echo
" "
;
// / n works here
echo
"This is a simple string."
;
echo
" "
;
// Variables included directly
$string
=
’ABC’
;
echo
"The word is $string."
;
?>
Output:I am a geek. It’ll be interesting to know about the string. This is a simple string. The word is ABC.