Copy codeThe Code is as follows: <? Php
/************ By garcon1986 *********/
// Difference between print and echo:
// 1. echo can input multiple strings, but print cannot.
Print "hello". "world"; // succeeded
Echo "hello". "world"; // success
// Print "hello", "world"; // failed
Echo "hello", "world"; // success
// 2. echo is faster than print.
$ Stime = microtime (true );
Print "hello". "world ";
$ Etime = microtime (true );
$ Total = $ etime-$ stime;
Echo $ total. '<br/> ';
// Microtime-Return current Unix timestamp with microseconds
$ Stime2 = microtime (true );
Echo "hello". "world ";
$ Etime2 = microtime (true );
$ Total2 = $ etime2-$ stime2;
Echo $ total2. '<br/> ';
// Execution result:
// Helloworld0.0014331340789795
// Helloworld0.00018310546875
// The echo is faster than print.
// Print_r-Prints human-readable information about a variable or Array
$ A = "sajfd sfjal sfjalwureoi weu sj we fk io ";
Print_r ($ );
Echo '<br/> ';
$ A = array ("B", "c", "d ");
Print_r ($ );
Echo '<br/> ';
// Var_dump-Dumps information about a variable or Array
// Var_dump -- print information about the variable
$ A = "sajfd sfjal sfjalwureoi weu sj we fk io ";
Var_dump ($ );
Echo '<br/> ';
$ A = array ("B", "c", "d ");
Var_dump ($ );
Echo '<br/> ';
Var_dump (array ("B", "c", "d "));
Echo '<br/> ';
?>
<? Php
/************ By garcon1986 ********/
// %-Return percentage sign
// % B-binary number
// % C-ASCII characters
// % D-Signed decimal number
// % E-resumable counting (such as 1.5e + 3)
// % F-floating point number (local settings aware)
// % F-floating point number (not local settings aware)
// % O-Octal numbers
// % S-string
// % U-Unsigned decimal number
// % X-hexadecimal (lowercase letter)
// % X-hexadecimal (uppercase letters)
// The printf () function outputs formatted strings.
$ Str = "hello ";
$ Number = 456;
// Example1
Printf ("% s world. Day number % s", $ str, $ number); // output: hello world. Day number 456
Print "<br/> ";
// Example2
Printf ("%", $ number); // %
Print "<br/> ";
Printf ("% B", $ number); // 111001000.
Print "<br/> ";
Printf ("% c", $ number); // ascii code
Print "<br/> ";
Printf ("% d", $ number); // 456.
Print "<br/> ";
Printf ("% e", $ number); // 4.5620.e + 2
Print "<br/> ";
Printf ("% f", $ number); // 456.000000.
Print "<br/> ";
Printf ("% F", $ number); // 456.000000.
Print "<br/> ";
Printf ("% o", $ number); // 710.
Print "<br/> ";
Printf ("% s", $ number); // 456.
Print "<br/> ";
Printf ("% u", $ number); // 456.
Print "<br/> ";
Printf ("% x", $ number); // 1c8
Print "<br/> ";
Printf ("% X", $ number); // 1C8
Print "<br/> ";
Printf ("With 2 decimals: % 1 \ $. 2f <br/> With no decimals: % 1 \ $ u <br/>", $ number );
// With 2 decimals: 456.00
// With no decimals: 456
Printf ("With 2 decimals: % f <br/> With no decimals: % 1 \ $ u <br/>", $ number );
// With 2 decimals: 456.000000
// With no decimals: 456
// The fprintf () function writes formatted strings to the specified output stream (for example, a file or database ).
$ File = fopen ("text.txt", "w ");
Echo fprintf ($ file, "fprintf 1: % s world. Day number % u", $ str, $ number). '<br/>'; // 38
Echo fprintf ($ file, "fprintf 2: % f", $ number). '<br/>'; // 21
Echo fprintf ($ file, "fprintf 3: With 2 decimals: % 1 \ $. 2f \ nWith no decimals: % 1 \ $ u ", $ number ). '<br/>'; // 56
// The vprintf () function outputs formatted strings.
// The arg parameter in vprintf () is located in the array. The element of the array is inserted into the percentage (%) symbol of the Main string. This function is executed step by step. In the first % symbol, insert arg1, at the second % symbol, insert arg2, and so on.
Vprintf ("vprintf: % s world. Day number % u", array ($ str, $ number); // vprintf: hello world. Day number 456
Echo '<br/> ';
// The sprintf () function writes formatted strings into a variable.
$ Txt = sprintf ("sprintf: % s world. Day number % u", $ str, $ number );
Echo $ txt. '<br/>'; // sprintf: hello world. Day number 456
// Vfprintf () Operates as fprintf () but accepts an array of arguments, rather than a variable number of arguments.
Echo vfprintf ($ file, "vfprintf: % s world! Day number % u ", array ($ str, $ number). '<br/>'; // 37
// Vsprintf () Operates as sprintf () but accepts an array of arguments, rather than a variable number of arguments.
$ Txt = vsprintf ("vsprintf: % s world. Day number % u", array ($ str, $ number ));
Echo $ txt. '<br/>'; // vsprintf: hello world. Day number 456
?>