It is the way to see the processed php data by sending it to the browser as an out put. You can display the contents within the browser to see the users. There are several ways allows in php to send out put to the browser. I'm discussed here most important & common methods here.
<?php
echo "Hello world!..."; // echo() statement with single argument.
echo "Hello ", "world!..."; // echo() statement with two arguments.
?>
~ OR ~
<?php
$str1 = "Hello ";
$str2 = "world!...";
echo $str1, $str2; // echo() statement with two variables.
?>
This method send only 1 string argument to the browser. print() statement accept multiple strings as a single argument.
syntax:
print (string arg);
Ex:
<?php
print "Hello world!..."; // print() statement with single argument.
print "Hello " . "world!..."; // print() statement with concatenated two strings.
?>
~ OR ~
<?php
$str1 = "Hello ";
$str2 = "world!...";
print $str1 . $str2; // print() statement with concatenated two variables.
?>
This method allows you to define the format of the data send the browser. printf() statement more conveniant when you are using with numbers .
syntax:
printf (string format[ , arg1, arg2, .... ]);
Ex:
<?php
printf ("Hello %s world!...","nice"); // printf() statement with string argument.
printf ("Value is %f ", 5.10); // printf() statement with decimal argument.
Output: Value is 5.1 // This output formatted as the number with single decimal place.
printf ("Value is %.2f ", 5.10);
Output: Value is 5.10 //This output formatted with two decimal places.
?>
No comments:
Post a Comment