This article describes the PHP common string output method. Share to everyone for reference, specifically as follows:
1. Echo Usage: Use echo to output directly or echo () output, no return value
$string = "<b> bold display text </b>", Echo $string;//echo "<br/>";//echo ($string);//Effect echo "<br/>"; echo "This", "is", "Echo test!"; /echo outputs multiple strings separated by commas echo "<br/>";
2. Print usage: Same as echo, just print runs slower than Echo and can only output one string at a time, always returning 1
$string = "<b> bold display text </b>";p rint $string;//print "<br/>";//print ($string);//Effect ditto print "<br/> ";
3. printf: Formatting the output string
/*%%-Returns a percent sign%%b-the binary number%C-ASCII value corresponding to the character%d-contains the signed decimal number (negative, 0, positive)%e-use lowercase scientific notation (for example 1.2e+2)%e-use uppercase scientific notation (e.g. 1.2E+2)%u- Decimal number without sign (greater than or equal to 0)%f-floating-point number (local setting)%f-floating point (non-local setting)%g-shorter%e and%f%g-shorter%e and%f%o-eight decimal number%s-string%x-16 decimal (lowercase)%x-16 in System number (capital letter) */$num =23;printf ("printf output floating point:%f", $num);//output: 23.000000printf ("<br/>");p rintf ("printf Output 2-bit decimal floating-point number:%1 \$.2f <br/>printf output No decimal digits:%1\ $u ", $num);//output: 23.00printf (" <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, and the age is 20.
I hope this article is helpful to you in PHP programming.