Summary of the types of PHP print functions. Print function 1 echo () in PHP to output multiple strings at the same time. multiple parameters are allowed without parentheses and no return value is required. PHP print function 2 print () can only output one string at a time
PHP print function 1 echo ()
Multiple strings can be output at the same time, and multiple parameters are allowed. parentheses are not required and no return value is required.
PHP print function 2 print ()
Only one string and one parameter can be output simultaneously. parentheses are required and return values. flase is returned when execution fails. the usage of print is similar to that of C language, so it will make a special explanation of % in the output content.
PHP printing function 3 die ();
There are two functions: output the content first, and then exit the program. (Commonly used in linking servers and databases)
Mysql_connect ("locahost", "root", "root") or die ("link server failed! ");
PHP print function 4 printf ();
Printf ("parameter 1", parameter 2): parameter 1 = output in what format; parameter 2 = output variable. ($ S: by string; $ d: by integer; $ B: By binary; $ x: by hexadecimal; $ o: by octal; $ f: by floating point)
- <? Php
- $ Num = 100.001;
- Printf ("% d", $ num); // 100
- Printf ("% s", $ num); // 100.001
- Printf ("% s --- % d --- % B --- % x --- % o --- % f", $ num)
- // 100.001 --- 100---1100100---64---144---1001.00100
- Printf ("%. 2f", $ num); // 100.00 (2 decimal places)
- Printf ("%. 1f", $ num); // 100.0 (one decimal point)
- Printf ("% '#10 s", $ num); // #### 100.001
- Printf ("% '@ 10 s", $ num); // @ 100.001
- Printf ("% '_ 10 s", $ num); // ___ 100.001
- Printf ("% '#-10 s", $ num); // 100.001 ###
- Printf ("% '@-10 s", $ num); // 100.001 @@@
- Printf ("% '_-10 s", $ num); // 100.001 ___
- Printf ("% '#20 s", $ num); // ############# 100.001
- ?>
PHP print function 5 sprintf ();
This cannot be output directly. assign a variable first and then output the variable.
- < ?php
- $num=100.001;
- $a=sprintf("%d",$num);
- echo $a; //100
- ?>
PHP print function 6 print_r ();
Function: only outputs an array.
PHP print function 7 var_dump ();
Function: output the content of a variable, type or string, type, and length. It is often used for debugging.
- < ?php
- $a=100;
- var_dump($a); //int(3) 100
- ?>
PHP print function 1 echo () can output multiple strings at the same time. it can have multiple parameters without parentheses and no return value. PHP print function 2 print () can only output one string at a time ,...