String concatenation is the string manipulation method when you join 2 or more strings together.
In PHP it is a quite easy task. You can use the concatenation operator which is the ‘.’ (dot). You can join 2 or more strings into one as follows:
$str1 = ‘This’;
$str2 = ‘is a’;
$str3 = ‘string’;

$full = $str1.‘ ‘.$str2.‘ ‘.$str3;

echo $full; // This is a string
Besides this you can use the operator to append a string to an existing one like this:
$str = ‘Main string’;
$str .= ‘ plus another string’;

echo $str; // Main string plus another string
If you concatenate a string with a number, the number will (automatically) be converted into a string value, so the output will be “string”:
$num = 100;
$str = $num.‘ is a number’;

echo $str; // 100 is a number

6 Years
Discussion Span
Last Post by R0bb0b

What are you doing? Posting a tutorial? If so, at least make it comply with the forum guidelines. Use code tags.


I'm so glad, but there are places for gloating about what you've just learned and this isn't it.

Edited by R0bb0b: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.