Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Output function in PHP:-

PHP uses four different types of functions to display output.

1)  echo:-   It is used to print multiple statements using a PHP script.


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.



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.


printf("%d",12.345)   //12
printf("%.2f",12.3456789)   //12.34
printf("%s","hello")  //hello


Another Example?

print 12.2345678;  //not possible till 2digit
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.

echo "<body bgcolor='cyan'>";
$a = sprintf("%.2f",12.2345678);
echo $a,"<br>";
print $b;

echo "</body>";

Complete Explanation of all output function using Single Program:-

Output function in PHP

echo "hello","world &nbsp;&nbsp;&nbsp;","welcome ","<br>";
print("welcome in php <br>");
print "welcome <br>";
echo ("scs <br>");
$s = sprintf("%.2f",$a);
echo $s;


Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post