How to Combine Two Strings in PHP The PHP programming language uses dot (.) operator to create singe string by combining two strings. This operator is specifically designed for strings. You can use this operation in multiple ways. Example 1:
1 2 3 4 5 6 7 8 9 | <?php // A sample php script to demonstrate contamination // of two strings in PHP $str1 = "Welcome"; $str2 = "Tecadmin!"; $result = $str1 . " " . $str2; echo $result; // Output: Welcome Tecadmin! ?> |
You can also concatenate one string and other string variable. For example:
1 2 3 4 5 | <?php $str1 = "Welcome"; $result = $str1 . " Tecadmin!"; echo $result; // Output: Welcome Tecadmin! ?> |
You can also concatenate with assignment operator (‘.=’), which appends the argument on the right side to the argument on the left side. For example:
1 2 3 4 5 | <?php $str1 = "Welcome"; $str1 .= " Tecadmin!"; echo $str1; // Output: Welcome Tecadmin! ?> |