Page 1 of 1

String Concatenation

New postPosted: Thu Mar 27, 2008 10:37 pm
by Ranman
Code: [Select all] [Expand/Collapse] [Download] (Untitled)
General form:

   Single-quoted strings are taken as literals

   Double-quoted Strings
    -they can include backslash escaped characters like \n, \r, etc.
    -they can also include variables, and they will replaced

   "Concatenation" means joining two Strings into one
   String concatenation - the dot operator


Q. What is the diffrence between " and '?
A. By example:

   This will print "This is a text string."

<?
$string = "is a";
$text = "This $string text string.";
echo $text;
?>


   This will print "This $string text string."

<?
$string = "is a";
$text = 'This $string text string.';
echo $text;
?>


Example 1:

   The following prints "Some text then PHP"

<?
$a = "PHP";
echo $b = "Some text then $a";
?>


Example 2:

   The following prints "There are 31 days in this month"

<?
$str = "There";
$str = $str." are ";
$str .= date("t");
$str .= " days in this month.";
echo $str;
?>


Example 3:

   The following prints "The value or the variable $var is 5."

<?
$var = 5;
$str = 'The value or the variable $var is '.$var.'.';
echo $str;
?>