1 echo (); 2 print (); 3 die (); 4 printf (); 5
Sprintf (); 6 print_r (); 7 var_dump ();
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.
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, so it will explain the % in the output content.
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 ("An error occurred while connecting to the server! ");
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: floating point type)
<? 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
(Keep 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
?>
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
?>
6 print_r ();
Function: only outputs an array.
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
?>