Table of Contents
To concatenate, or combine, two strings you can use the . operator:
<h2>Concatenate Strings</h2>
<p>From w3schools.com, Experiment by Teeratus_R </p>
<h4>String Concatenation</h4>
<?php
$txt1 = "Hello";
$txt2 = "world!";
echo $txt1 . $txt2;
?>
<p>The result of the example above is HelloWorld, without a space between the two words.
You can add a space character like this:</p>
<?php
$x = "Hello";
$y = "World";
$z = $x . " " . $y;
echo $z;
?>
<p>An easier and better way is by using the power of double quotes.
By surrounding the two variables in double quotes with a white space between them, the white space will also be present in the result:</p>
<?php
$x = "Hello";
$y = "World";
$z = "$x $y";
echo $z;
?>
Result View Example
Document in project
You can Download PDF file.