Title: String Concatenation
Contributor: Randall Goguen (aka Ranman)
Last Update: Tuesday July 18 19:25 EDT 2000
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;
?>
Anyone who wishes to make additions or changes to this
PHP Tip email them to webmaster@linuxguruz.org
This document is Copyright (c) 1999 by LinuxGuruz