SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP String Functions

String adding in PHP

We can add two strings and generate a new string in PHP by using a single dot. This way we can add any number of strings by using " . " ( dot ) in between them. We will learn different types of string addition in PHP. Let us start with simple adding of two strings by using a single dot between them. Here is the example.

$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 ".
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;

Number of User Comments : 1


Google+
rajesh28-06-2010
Good useful article.
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer