PhP100 excellent: PhP printing function set

Source: Internet
Author: User

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
?>
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.