String adding in PHP

$string1="Welcome to plus2net.com";
$string2=" PHP  section ";
$string=$string1.$string2;
echo $string;
The out put of the above command will give the full sentence
Welcome to plus2net.com PHP section 
We can add any number of strings by using " . " ( dot ) in between them.

Now let us learn how we can add different strings to a common string variable. Here is the code.
$string= " Hello, ";
$string .=" Welcome to ";
$string .=" plus2net.com ";
echo $string;
The above code will print all the strings one after other forming the complete sentence.

We can merge one string inside another string like this.

$string2=" PHP  section ";
$string= "Welcome to plus2net.com $string2";
echo $string;
Here the code will display full string with string2 value added at the end. But this way we can't add function inside a string. Let us try to add one function to display present date inside the welcome message. Here like a string we can't add. The following line won't display today's date along with the string. This is not going to work .
$string= "Welcome to plus2net.com $string2 today on date('m/d/y')";
We have to modify the above line like this to display current date.
$string= "Welcome to plus2net.com $string2 today on  ". date("m/d/y");
echo $string;
Output is here
Welcome to plus2net.com  PHP  section  today on  10/15/25

Example: Concatenating Multiple Strings Dynamically

$str1 = "Hello";
$str2 = "World!";
echo $str1 . " " . $str2;  // Output: Hello World!

Example: Concatenating Numeric Strings

$num1 = "100";
$num2 = "50";
echo $num1 . $num2;  // Output: 10050

String Functions first letter of every word to capitalize by using ucwords Change all alphabetic chars to lowercase Checking all lower case or upper case chars in a string
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







rajesh

28-06-2010

Good useful article.




PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer