Home Tutorial Php PHP Echo Variables

 
 

Share on Google+Share on Google+
PHP Echo Variables
Posted on: January 12, 2010 at 12:00 AM
Advertisement
Echo() is used to display the output of your program. It is not a function so, it is not necessary to use parenthesis after echo. If you want to passed more than one variable to display then it shouldn't be enclosed within parenthesis.

PHP Variables Echo

PHP Echo() Function is used to display the output of your program. It is not a function so, it is not necessary to use parenthesis after echo. If you want to passed more than one variable to display then it shouldn't be enclosed within parenthesis. Echo() doesn't react like a function, it is moreover used as a language constructor. It can output all types of data and multiple outputs can be through only one echo() command. For example :

<?php

$hello = "Hello People!";

echo $hello ;

echo " to the world of web development.";

?>

The output of the above example is : Hello People! to the world of web development.

The above example is so simple, we store the a string value in $hello variable and in the next line, I used echo() command to display the output. The other line also display the string value without using variable. It means you can display multiple number of output with the help of echo command. Suppose, you have multiple variable and string, integers, array or class and want to display without using echo command again and again. Let see the example :

<?php

$hello = "Hello People";

$name = "Suraj Mittal";

$age = "22";

echo $hello." My name is ".$name.". I am ".$age." years old, working as a Web Developer.";

?>

The output of the above example is : Hello People My name is Suraj Mittal. I am 22 years old, working as a Web Developer.

In the above example we used multiple numbers of variables to display using only one echo command and concatenate to all of them with the help of dot operator. Lets move towards little bit complex programming. For example :

<?php

$today = date("d-m-y");

$time = date("H:i:s");

$browser = $HTTP_USER_AGENT;

$name = "Suraj Mittal";

echo "Hello ".$name;

echo " It is ".$time." and the Date is ".$today. ". Your Browser is ".$browser;

?>

The output of the above example is : Hello Suraj Mittal! It is 06:25:28 and the Date is 12-01-10. Your Browser is Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7

 If you notice in the above we used  date function to display the today date and time and $browser variable to display the version of your browser and rest of the items are same.

Advertisement

Related Tags for PHP Echo Variables :


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 12, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com