PHP

How to Concatenate two or more string in PHP

We can concatenate two or more string in PHP by concatenation operator(“.”);
Example 1 :

<?php
$string1="Hello";
$string2="World !!";
$string3=$string1.$string2;
echo $string3;
?>

Output : HelloWorld !!
Example 2:  if you want to add space between two strings

<?php
$string1="Hello";
$string2="World !!";
$string3=$string1." ".$string2;
echo $string3;
?>

Output : Hello World !!
Example 3:  Concatenate more than two strings

<?php
$string1="Welcome to";
$string2="PHPGurukul";
$string3="Programming Blog";
$string4=$string1.$string2.$string3;
echo $string4;
?>

Output : Welcome to PHPGurukul Programming Blog

Recommended Tutorials for you


Related posts

How to insert data into MySql using PHP

Anuj Kumar

How to Fetch data from database Using OOPS In PHP

Anuj Kumar

How to upload and validate a image in php

Anuj Kumar

Adding Comments to PHP Code

Anuj Kumar

How to prevent Cross-Site Request Forgery (CSRF) in PHP

Anuj Kumar

Implode() and Explode() Function in PHP

Anuj Kumar

PHP – Unique Features

Anuj Kumar

How to Salt & Hash a Password using Sha256

Anuj Kumar

4 comments

paras shah November 10, 2018 at 5:16 am

sir double quote is missing in Example 3 “Concatenate more than two strings”

Reply
Anuj kumar November 10, 2018 at 5:17 am

Issue fixed

Reply
paras shah June 26, 2018 at 11:40 am

sir double quote is missing in Example 3 “Concatenate more than two strings”

Reply
Anuj kumar June 26, 2018 at 3:43 pm

Issue fixed

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.