- Instant help with your Php coding problems

PHP string concatenation

String concatenation is the string manipulation method when you join 2 or more strings together. In PHP it is quite easy task. You can use the concatenation operator which is the '.' (dot). You can join 2 or more strings into one as follows:

<?php
   $str1 = 'This ';
   $str2 = 'is a ';
   $str3 = 'test string';
 
   $full = $str1.$str2.$str3;
 
   echo $full;
?>

Besides this you can use the operator to append a string to an existing one like this:

<?php
   $str  = 'This is the base string';
   $str .= ' and this was appended';
 
   echo $str;
?>

If you concatenate a number with a string then the number will be converted into a string value so the output will be a string as follows:

<?php
   $i = 100;
   $str = $i.' is a number';
 
   echo $str;
?>

Share "PHP string concatenation" with your friends