CONCATENATION: HOW TO JOIN STRINGS IN PHP
It is possible to join strings in PHP and this process is referred to as Concatenation.
Example:
$string1="John";
$string2="Smith";
$joinedString=$string1.$string2;
echo $joinedString;
Notice that we used a . to join the strings. The above will output JohnSmith. Notice that the words JohnSmith have no space in them. To give it a space, do as follows:
$string1="John";
$string2="Smith";
$joinedString=$string1." ".$string2;
echo $joinedString;
The above will now output John Smith.
You can also add to an existing string using .= as follows:
$string ="John";
$string .="Smith";
echo $string;
This will output JohnSmith. To add a space betwen John and Smith,
$string ="John";
$string .=" ";
$string .="Smith";
echo $string;
This will output John Smith. Another way to add a space,
$string ="John";
$string .=" Smith";
echo $string;
This will output John Smith. Note the space before Smith in the second $string.
|