Saturday, 19 October 2013

Concatenation in php

Concatenation in php
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(Screenshot1)
1
2
3
4
5
6
7
<?php
$day = 'Thursday';
$date = 31;
$year = 2011;
 
echo '<span id="IL_AD4" class="IL_AD">The date</span> is '.$day.' '.$date.' ' .$year;
?>
Output (Screenshot2) :-
Concatenation in php
Concatenation(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):-
Concatenation in php
Concatenation(Screenshot3)
1
2
3
4
5
6
7
<?php
$day = 'Wednesday';
$date = 30;
$year = 2011;
 
echo 'The date is '.$day.' '.$date.' ' .$year;
?>
Output (Screenshot4) :-
Concatenation in php
Concatenation(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
Concatenation(Screenshot5)
1
2
3
4
5
6
7
<?php
$day = 'Wednesday';
$date = 30;
$year = 2012;
 
echo 'The date is <strong>'.$day.' '.$date.' ' .$year.'</strong>;
?>
Output (Screenshot6):-
Concatenation in php
Concatenation(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
Concatenation(Screenshot7)
1
2
3
4
5
6
7
<?php
$day = 'Wednesday';
$date = 30;
$year = 2011;
 
echo "The date is $day $date $year";
?>
Output (Screenshot4) :-
Concatenation in php
Concatenation(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
Concatenation(Screenshot8)
1
2
3
4
5
6
7
<?php
$day = 'Wednesday';
$date = 30;
$year = 2011;
 
echo 'The date is $day $date $year';
?>
output (Screenshot9):-
Concatenation in php
Concatenation(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.

Read More Extra Tutorials

No comments:

Post a Comment