Summary of 4 functions for PHP to output content to browser

  • 2021-08-03 09:45:14
  • OfStack


<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<?php
/*
 * 0x01:print() Statement
 * int print(arguments);
 * print() Statement outputs the data passed into it to the browser
 */
print("<p>I love PHP!!!</P>");
print "<p>I love PHP!!!</p>";
?>
<?php
/*
 * 0x02:echo() Statements, functions and print() Function of function 1 Sample
 * They all output data to the browser
 * echo() Efficiency ratio of function execution output print() Function is slightly more efficient 1 Point, because echo Do not return results
 */
echo "<p>I love PHP!!!</p>";
$languge="Java";
echo "<p>I love $languge!!!</P>";
?> <?php
/*
 * 0x03:printf() Statement
 * If you want to output any static text and 1 A mixture of dynamic information stored in two or more variables, using printf() Function is ideal
 * printf() Function divides static data and dynamic data into two parts, which are as follows:
 * integer printf(string format [,mixed args]);
 */
printf("<p>I love %s!!!</P>","C#");
/*
 * In the above example %s Yes 1 Placeholders, the commonly used placeholders are listed below
 * Type           Describe
 * %b      Consider parameters as 1 Integer, displayed as 2 Binary number
 * %c      Consider parameters as 1 Integer, displayed as the corresponding ASCII Character
 * %d      Consider parameters as 1 Integer, displayed as a signed 10 Binary number
 * %f      Consider parameters as 1 Floating-point numbers, displayed as floating-point numbers
 * %o      Consider parameters as 1 Integer, displayed as 8 Binary number
 * %s      Consider the parameter as a string and display it as a string
 * %u      Consider parameters as 1 Integers displayed as unsigned integers
 * %x      Consider parameters as 1 Integer, displayed as lowercase 16 Binary number
 * %X      Consider parameters as 1 Integer, displayed as uppercase 16 Binary number
 */
$num=1024;
printf("<p>%b:%c:%d:%f:%o:%s:%u:%x:%X</p>",$num,$num,$num,$num,$num,$num,$num,$num,$num);
?>
<?php
/*
 * 0x04:sprintf() Statement
 * sprintf() Function in printf Function of function 1 Sample, but it assigns the output value to the 1 Instead of directly outputting to the browser
 * This function is very useful, such as formatting strings with dynamic output, combining the placeholders above, and making binary conversion in the form of:
 * string sprintf(string format [, mixed args]);
 */
$cost=sprintf("$%.2f",43.2);//$cost=$43.20
?>
</body>
</html>


Related articles: