How to Concatenate Two Strings in PHP?

Last updated on August 24, 2023

The concatenation operator (‘.’) is mostly used in PHP to concatenate the strings. We can concatenate any kind of value through the concatenation operator.

Example 1:

Let’s concatenate the string.

"John Smith";
" is Software Engineer";

In this example, we have two strings that need to be concatenated. To concatenate them we can use the concatenation operator (‘.’).

echo "John Smith"  .  " is Software Engineer";
// Output: John Smith is Software Engineer

Above we concatenated both strings without using any variable. In the next example, we will be storing both strings in the variable and concatenating them through the concatenation operator (‘.’).

Simple PHP String Concatenation

Example 2:

Let’s store both strings into the variables and then concatenate them.

$name = "John Smith";
$profession = " is Software Engineer";

In this example, we have two variables $name and $profession that store two different strings. To concatenate them, we are using the concatenation operator.

echo $name . $profession;
// Output: John Smith is Software Engineer
Concatenate strings and varibles in PHP


Written by
I am a skilled full-stack developer with extensive experience in creating and deploying large and small-scale applications. My expertise spans front-end and back-end technologies, along with database management and server-side programming.

Share on:

Related Posts

Tags: PHP, String,