How to use Concatenation operator in Php


In php Concatenation operator is used to combine two or more string value or float value or integer value or string and integer value or float and integer value. In php ( . ) dot sign used as concatenation operator to combine the two or more value. See the below examples

Example1
Lets take three variables containing some value
<!DOCTYPE html>
<html>
<head><title>expertcoding.com</title>
</head>
<body>
<?php
$a = "You are seeing";
$b = "the example of";
$c = "php Concatenation operator";
// now we want display all these value in a single sentence in browser using Concatenation operator
echo $a . " " .$b . " " . $c;
// here (" ") is used to provide white space 
?>
</body>
</html>

Example2
<!DOCTYPE html>
<html>
<head><title>expertcoding.com</title>
</head>
<body>
Ram brings 12 bananas worth Rs 50.5
Below are the several example for displaying the above sentence
<?php
echo "Ram brings 12 bananas worth Rs 50.5";
             //OR

echo "Ram brings" . " " . "12 bananas" . " " . "worth Rs" . " " . "50.5";
                 //OR
//  by assigning the value in variable
$a = "Ram brings";
$b = "12 bananas";
$c = "worth Rs";
$d = 50.5;
echo $a . " " .  $b . " " . $c . " " . $d;
                   //OR
echo $a . " " . "12 bananas" . " " . $c . " " . "50.5";
?>
</body>
</html>

Php Concatenation Operator


In php Concatenation operator is used to combine two or more string value or float value or integer value or string and integer value or float and integer value. In php ( . ) dot sign used as concatenation operator to combine the two or more value. See the below examples

Example1
Lets take three variables containing some value
<!DOCTYPE html>
<html>
<head><title>expertcoding.com</title>
</head>
<body>
<?php
$a = "You are seeing";
$b = "the example of";
$c = "php Concatenation operator";
// now we want display all these value in a single sentence in browser using Concatenation operator
echo $a . " " .$b . " " . $c;
// here (" ") is used to provide white space 
?>
</body>
</html>

Example2
<!DOCTYPE html>
<html>
<head><title>expertcoding.com</title>
</head>
<body>
Ram brings 12 bananas worth Rs 50.5
Below are the several example for displaying the above sentence
<?php
echo "Ram brings 12 bananas worth Rs 50.5";
             //OR

echo "Ram brings" . " " . "12 bananas" . " " . "worth Rs" . " " . "50.5";
                 //OR
//  by assigning the value in variable
$a = "Ram brings";
$b = "12 bananas";
$c = "worth Rs";
$d = 50.5;
echo $a . " " .  $b . " " . $c . " " . $d;
                   //OR
echo $a . " " . "12 bananas" . " " . $c . " " . "50.5";
?>
</body>
</html>

How to define variable in php


To define variable in php '$' sign is used followed by variable name. Unlike other programming language in php we don't need to define the data type of the variable it get auto assigned whether it is string value or integer value or floating value depending upon the value assigned to variable  by the user. This will very clear while seeing the example below.

Example
<!DOCTYPE html>
<html>
<head><title>expertcoding.com</title>
</head>
<body>
<?php
echo $example = "hello world";     // string value
echo $example1 = 10 ;                 // integer  value
echo $example2 = 10.03;            // floating value
?> 
</body>
</html>
 We can clearly see that we don't  need to define the data type it get auto defined according to the value assigned to the variable by the user.

Output
hello world
10
10.03

php print_r function


To display an array element in php you cannot use 'echo' function or 'print' function.To display an array elements in php we use another inbuilt function known 'print_r' using this function you can display the array elements.

<!DOCTYPE html>
<head><title>expertcodingmaster.com</title>
</head>
<body>
<?php
$example  =  array ('mukesh' , 'ankita' , 'prashant') ;
echo     "<pre>" ;
print_r ($example) ;
echo    "<pre>" ;
? > 
</body>
</html>
</html>

Output  screen
Array
(
    [0] => mukesh
    [1] => ankita
    [2] => prashant
)

How to display Array element in php


To display an array element in php you cannot use 'echo' function or 'print' function.To display an array elements in php we use another inbuilt function known 'print_r' using this function you can display the array elements.

<!DOCTYPE html>
<head><title>expertcodingmaster.com</title>
</head>
<body>
<?php
$example  =  array ('mukesh' , 'ankita' , 'prashant') ;
echo     "<pre>" ;
print_r ($example) ;
echo    "<pre>" ;
? > 
</body>
</html>

Output  screen
Array
(
    [0] => mukesh
    [1] => ankita
    [2] => prashant
)

php code to display anything


To display anything in php one can use its inbuilt function 'echo' or 'print'. You can display anything using this keywords whether it is string value or integer value or float value.

How to use ' echo ' function/keyword to display anything
<!DOCTYPE html>
<html>
<head><title>expertcodingmaster.com </script>
</head>
<body>
<?php
echo "hello world";   // string value;
echo  10;                   // integer value;
echo   "<script>alert('echo example')</script>";     // java script
?>
</body>
</html>

How to use 'print' function/keyword to display anything
<!DOCTYPE html>
<html>
<head><title>expertcodingmaster.com </title>
</head>
<body>
<?php
print "hello world";   // string value;
print  10;                   // integer value;
print   "<script>alert('echo example')</script>";     // java script
?>
</body>
</html>

Now you are must thinking both the function are same then what is the difference between them. Actually there is no difference between 'echo' and 'print' function but the 'print' function has one limitation. The 'echo' function can work with more than one string or expression at a time but the 'print' function cannot work with more than one string or expression at a time. This will be more clear after seeing the example below.
<!DOCTYPE html>
<html>
<head><title>expertcodingmaster.com </title>
</head>
<body>
<?php
echo "Hello","world";  
print "Hello","world";   // this will show you an error
?>
</body>
</html>

The 'print' function can display only one string at a time. The speed of 'echo' function is more tan the 'print' function

Apart from this two display function one more display function is available in php Print_r ( ). This function is used to display the array element. See the below example
<!DOCTYPE html>
<html>
<head><title>expertcoding.com</title>
</head>
<body>
<?php
$example = array('mukesh','prashant','sachin','arpana','ankita');
echo "<pre>";
print_r($example);
?>
</body>
</html>

The above code will show you the output
Array
(
    [0] => mukesh
    [1] => prashant
    [2] => sachin
    [3] => arpana
    [4] => ankita
)

These three function are mainly available in Php to display data in browser

Php Syntax


A php script is executed on the server, and the plane HTML result is sent back to the browser.
A php script starts with '<?php' and end with '?>' .

<?php
// all php scripts are written within the opening and closing tag of php
?>

Below is the example of simple php script to display "HELLO INDIA"
<!DOCTYPE html>
<html>
<head><title>expertcoding.com</title>
</head>
<body>
<?php
echo "HELLO INDIA";
?>
</body>
</html>
The php files are  save with '.php' extension . Copy the above code in notepad and save as simple.php.

Now create a new folder myprojrct in www folder of wampserver and pest the simple.php in myproject folder. www folder is located at the place where you have install the wampserver. If you are not able to find the file location just right click on wampserver icon located on desktop and click on property option one popup window will be open in that file location will be mention under the target option.

NOTE :- What ever php file you want to run in browser it must be located in www folder.


Now create new folder over hare and copy the simple.php file in that folder


Now lets see the output in the browser, for that at first run start the wampserver and open the localhost by clicking on wampserver  icon available at tray.


After clicking on the localhost this page will be open in the browser in that you will find a option your project in that option you will all the folder name created on www folder now open your folder by clucking on it.


Now you will all the php file containing in that folder now click on simple.php file to see the output


The above code will display "HELLO INDIA" in browser .


Php Wampserver installation


Introduction to Php :-
PHP is server side scripting language it was released in the year 1995. It was created by Rasmus Lerdorf. It is used to create dynamic and creative websites .

Why Should I use Php :-
There are many more languages are available in market like ASP.Net, Python etc . You must be thinking that why we are using Php apart from ASP.Net or Python . The reason behind this is, It is completely free to use and download. No need to purchase any type of license. It is completely and absolutely free . In another hand if you are using ASP.Net at first you need to purchase license from Microsoft. Also many of the CMS PHP base for example - WordPress, Drupal, Joomla etc. Today Php is mostly used in every website among this the most  famous websites like Facebook.com, Yahoo.com, Flickr.com, Wikipedia.org are also completely based on Php.

Before using Php you should have the basic knowledge of -
1)   HTML
2)   CSS
3)   JQuery (it is  optional )
4)   SQL

JQuery is completely optional but if you know JQuery you will get an advantage if you use JQuery with Php it will increase the processing speed of your website . So mainly to use PHP you need to know HTML, CSS and SQL only.

Installation of Wampserver :-
As earlier we have discuss that Php is server side scripting language . So we need to install Wampserver. For 64 bit machine install Wampserver of 64 bit and for 32 bit machine install Wampserver of 32 bit. The given below link will directly tack you to the downloading area of wampserver .

http://www.wampserver.com/en

After selecting your version you will get a popup window where you will get a  link of direct download.

To use Wempserver your machine must have latest version of 'Visual C++' redistributed  installed in you system.






download the wempserver and install it . After installing run the Wampserver as an Administrator. After that you will see wampserver icon in your system task-manager tray of green color. if color of icon is not green it indicates wampserver is not installed properly uninstall it and try reinstalling.




If you are using Skype then unchecked the incoming connection port because wampserver and Skype both uses the port 80 for the incoming server so it get conflict .




If still wampserver icon not turning into green try checking no other virtual server is running in your pc.