In PHP printing function 1 echo()
can output multiple strings at the same time and can have multiple parameters. , parentheses are not required, and there is no return value.
PHP printing function 2 print()
can only output one string and one parameter at the same time, requires parentheses, and has a return value. When its execution fails, it returns flase. The usage of print is very similar to that of C language, so % in the output content will be specially interpreted.
PHP printing function 3 die();
has two functions: first output the content, and then exit the program . (Commonly used in linked servers and databases)
mysql_connect("locahost","root","root") or die("Linked server failed!");
PHP printing function 4 printf();
printf("Parameter 1", Parameter 2): Parameter 1 = output format; Parameter 2 = output variable. ($s: according to string; $d: according to integer; $b: according to binary; $x: according to hexadecimal; $o: according to octal; $f: according to floating point)
<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>$</span><span class="attribute">num</span><span>=</span><span class="attribute-value">100</span><span>.001; </span></li><li class="alt"><span>printf("%d",$num); //100 </span></li><li><span>printf("%s",$num); //100.001 </span></li><li class="alt"><span>printf("%s---%d---%b---%x---%o---%f",$num,$num,$num,$num,$num,$num) </span></li><li><span>//100.001---100---1100100---64---144---1001.00100 </span></li><li class="alt"><span>printf("%.2f",$num); //100.00 (小数点保留2位) </span></li><li><span>printf("%.1f",$num); //100.0 (小数点保留1位) </span></li><li class="alt"><span>printf("%`#10s",$num); //###100.001 </span></li><li><span>printf("%`@10s",$num); //@@@100.001 </span></li><li class="alt"><span>printf("%`_10s",$num); //___100.001 </span></li><li><span>printf("%`#-10s",$num); //100.001### </span></li><li class="alt"><span>printf("%`@-10s",$num); //100.001@@@ </span></li><li><span>printf("%`_-10s",$num); //100.001___ </span></li><li class="alt"><span>printf("%`#20s",$num); //#############100.001 </span></li><li><span class="tag">?></span><span> </span></span></li></ol>
PHP printing function 5 sprintf();
This cannot be output directly, assign it to a first variable, and then output the variable.
<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>$</span><span class="attribute">num</span><span>=</span><span class="attribute-value">100</span><span>.001; </span></li><li class="alt"><span>$</span><span class="attribute">a</span><span>=</span><span class="attribute-value">sprintf</span><span>("%d",$num); </span></li><li><span>echo $a; //100 </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li></ol>
PHP printing function 6 print_r();
Function: only For output array.
PHP printing function 7 var_dump();
Function: Output the content, type or string content, type, length of the variable. Often used for debugging.
<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>$</span><span class="attribute">a</span><span>=</span><span class="attribute-value">100</span><span>; </span></li><li class="alt"><span>var_dump($a); //int(3) 100 </span></li><li><span class="tag">?></span><span> </span></span></li></ol>