Output function in PHP

0

PHP uses four different types of functions to display output.
1)  echo:-   It is used to print multiple statements using a PHP script.
<?php
echo "welcome","hello","xyz";
echo ("hello");
?>
it is mostly preferred to display output.
2) print:-   It is used to print a single statement using PHP Script.
<?php
print("welcome");  
print "welcome";
?>
3) printf():-   It is used to print formatted output means if we want to print data using format specifier %d,%f,%s then we can use printf() in PHP.
we can print only a single statement using printf.
<?php
printf("%d",12.345)   //12
printf("%.2f",12.3456789)   //12.34
printf("%s","hello")  //hello
?>
Another Example?
<?php
print 12.2345678;  //not possible till 2digit
print("<br>");
echo 12.2345678,"<br>";    //not possible till 2digit
printf("%.2f",12.2345678)  //possible
?>
sprintf():-  this method is used to return data in String format.
It is used to display data of one file to another file.
It is similar to printf() but it is return type function.
<?php
echo "<body bgcolor='cyan'>";
$a = sprintf("%.2f",12.2345678);
echo $a,"<br>";
$b=sprintf("welcome");
print $b;
echo "</body>";
?>
Complete Explanation of all output function using Single Program:-
Output function in PHP
<?php
echo "hello","world &nbsp;&nbsp;&nbsp;","welcome ","<br>";
print("welcome in php <br>");
print "welcome <br>";
echo ("scs <br>");
$a=12.345566666;
printf("%.2f<br>",$a);
$s = sprintf("%.2f",$a);
echo $s;
?>
Tags

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)