Concatenate strings in PHP using concatenation operator

July 31, 2010

Concatenation is the process of joining multiple strings into one.In PHP concatenate  strings is doing by concatenation operator ( “.” dot symbol ).Using of concatenation is highly used one in PHP programs. We need to use this for string concatenations and for printing the results in desired order etc.

Here is one Sample PHP program with Concatenate strings  using concatenation operator

<?php
$variable_1 =  "Syam";
$variable_2 = "is a PHP professional";
$variable_3 = "From India";
echo $variable_1." ".$variable_2." ".$variable_3;
?>

Output of this PHP program will look like
Syam is a PHP professional From India

In Some other cases we need to store the concatenated strings as a variable

See the following code

<?php
$variable_1 =  "Syam";
$variable_2 = "is a PHP professional";
$variable_3 = "From India";
$variable_4 = $variable_1." ".$variable_2." ".$variable_3;
echo $variable_4;
?>

In this code concatenated string is stored in the variable “$variable_4″  for later use in the program. Above code will ouput the same result as our previous example.

Related Tutorials


Array in PHP tutorial
Array is a special variable which can store multiple value. ( Note : a normal variable can store only one...
PHP Value Assignment Operators
Here we can learn about the operators used for assigning values in PHP. Operator “=” Usage Sample program <?php $x...
Variable Declarations in PHP
Variables are used for storing the data like strings, numbers , arrays etc in programs. In PHP a variable starts...
Adding line break using PHP
For the formatting purpose we need to add line breaks in our output or strings to store in MySQL tables...
PHP session tutorial
Using PHP session variable is a mechanism to store user’s data in server. And sessions will last till we are...
Arithmetic calculation operators in php
There are several operators in PHP available for arithmetic calculations and all. Addition Operator : + Use : For the...
PHP cookie tutorial with sample program
Cookie is a variable stored in the user computer. Its a mechanism to store the data for future use. Cookies...
strlen() – PHP string length function
While our PHP programming , in some cases we need to get the length of a string for processing. strlen()...

One Response to Concatenate strings in PHP using concatenation operator

  1. admin on July 31, 2010 at 9:46 am

    “” ( double quotes ) are used with concatenation operator to add HTML tags and other non PHP statements …

Leave a Reply