Sunday, 16 February 2014

Concatenation in php

concatenation
"Con","cat","en","ation"
This is tutorial for concatenation within php. Now if you ever come across working with concatenation you will come to know about it in a better way.Before programming you may understand how to concatenate different variables together.Later on, How to printvariables which are concatenated in,Its very very simple in php.

Code for Concatenate in php (Screenshot1):-

Concatenation in php
Concatenation in php Screenshot1
 <?php

$day = 'Thursday';

$date = 31;

$year = 2011;



echo 'The date is '.$day.' '.$date.' ' .$year;

?>

Output (Screenshot2) :- 

Concatenation in php
Screenshot2
 In this code of  concatenate in php I am creating three variables i.e. $day, $date, $year.Now to echo one or more variables we have to join variables with dot which is called as concatenate. In single quotation (‘) inside echo statement we are echoing variables and text.Blank single quotation (‘) is used to leave space between variables.With Single quotation (‘) concatenate feature is most useful and with Double quotation (“) too its easy which I will so you in later tutorials.

Code For Concatenate in php (Screenshot3):-

Screenshot3

<?php

$day = 'Wednesday';

$date = 30;

$year = 2011;



echo 'The date is '.$day.' '.$date.' ' .$year;

?>

Output (Screenshot4) :-




In this examples i just updated variables and its automatically update output.So this is harder but fastest way to echo out variables by concatenate in string data.

Code for concatenate in php (Screenshot5):-
Concatenation in php
 Screenshot4


In this examples i just updated variables and its automatically update output.So this is harder but fastest way to echo out variables by concatenate in string data.

Code for concatenate in php (Screenshot5):-

 
concatenation in php
Screenshot5

<?php

$day = 'Wednesday';

$date = 30;

$year = 2012;



echo 'The date is <strong>'.$day.' '.$date.' ' .$year.'</strong>;

?>


Output (Screenshot6):-

concatenation in php
Screenshot6

In this example i am including html tags strong tag with concatenate strings, variables and also html tags.In this code it will bold variables.

Code for Concatenate in php with Double quotation marks(Screenshot7):-

Concatenation in php
Screenshot7

<?php

$day = 'Wednesday';

$date = 30;

$year = 2011;



echo "The date is $day $date $year";

?>



Output (Screenshot4) :-

Concatenation in php
Screenshot4

In this example we used Double quotation marks to concatenate string and variables and its easy because here you don’t write any dot (.) or to leave space in single quotation marks. Its very easy to Concatenate with double quotation marks.But single quotation marks are faster.Concatenate looks complex code in understanding there so i am recommending to always use single codes.

Code for Concatenate in php (Screenshot8):-

Concatenation in php
Screenshot8

<?php

$day = 'Wednesday';

$date = 30;

$year = 2011;



echo 'The date is $day $date $year';

?>

output (Screenshot9):-

Concatenation in php
Screenshot9
In this code if we use single quotation mark without concatenate with dot (.) it will echo variable name and does not reference to variable values.


No comments:

Post a Comment

Thanks For Comment Will get you Soon..

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates