Home > Backend Development > PHP Tutorial > Summary of types of PHP printing functions_PHP tutorial

Summary of types of PHP printing functions_PHP tutorial

WBOY
Release: 2016-07-15 13:30:41
Original
1188 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446291.htmlTechArticlePrinting function in PHP 1 echo() can output multiple strings at the same time and can have multiple parameters, which is not required Parentheses, no return value. PHP printing function 2 print() can only output one string at the same time,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template