This article describes the PHP common string output method. Share to all of you for reference, specific as follows:
1. Echo Usage: Can be directly output with ECHO, or echo () output, no return value
$string = "<b> bold display text </b>";
echo $string;
echo "<br/>";
Echo ($string);//Effect ditto
echo "<br/>";
Echo ' This ', ' is ', ' echo test! '; /echo output multiple strings separated by commas
echo "<br/>";
2. Print usage: ditto echo, only print runs slower than Echo, and only one string at a time, always returns 1
$string = "<b> bold display text </b>";
Print $string;
print "<br/>";
Print ($string);//Effect ditto
print "<br/>";
3. printf: Format output string
* Percent
%-returns a percent semicolon%
%b-binary number
%c-ascii the character
%d-contains positive and negative decimal numbers (negative, 0, positive)
%e-Scientific notation using lowercase (for example, 1.2e+2)
%E-Use the scientific notation of uppercase (for example, 1.2E+2)
%u-a decimal number (greater than or equal to 0) that does not contain a positive sign
%f-floating-point numbers (Local settings)
%f-floating-point numbers (not local settings)
%g-Shorter%E and%f
%G-Shorter%E and%f
%o-Eight number of
%s-string
%x-16 (lowercase)
%x-16 (capital Letter)
*/
$num =23;
printf ("printf output floating-point number:%f", $num);//output: 23.000000
printf ("<br/>");
printf ("printf Output 2 decimal floating-point number:%1\$.2f <br/>printf output No decimal places:%1\ $u", $num);/output: 23.00
printf ("<br/>");
4. sprintf:
$name = "Tom";
$age =20;
$printstr =sprintf ("sprintf output: His name is%s, age is%u", $name, $age);
echo $printstr//output: His name is Tom, age is 20
I hope this article will help you with the PHP program design.