A summary of the types of PHP print functions _php Tutorial

Source: Internet
Author: User
Tags php print
In PHP Print function 1 echo ()

You can output multiple strings at the same time, multiple parameters, no parentheses, no return values.

PHP Printing function 2 print ()

You can only output one string at a time, one parameter, a parenthesis, a return value, and flase when its execution fails. Print is used in a similar way to the C language, so there is a special explanation for the% in the output content.

PHP Print function 3 die ();

There are two functions: output the content first, then exit the program. (commonly used in linked servers, databases)

Mysql_connect ("Locahost", "root", "root") or Die ("link server failed!") ");

PHP Print function 4 printf ();

printf ("Parameter 1", Parameter 2): Parameter 1 = output by what format; parameter 2= the output variable. ($s: by string, $d: by Integer, $b: by Binary, $x: by 16, $o: by octal; $f: by floating-point type)

 
 
  1. < ? PHP
  2. $ Num = - . 001;
  3. printf ("%d", $num); 100
  4. printf ("%s", $num); 100.001
  5. printf ("%s---%d---%b---%x---%o---%f", $num, $num, $num, $num, $num, $num)
  6. 100.001------1100100------144---1001.00100
  7. printf ("%.2f", $num); 100.00 (decimal point reserved 2 digits)
  8. printf ("%.1f", $num); 100.0 (decimal point reserved 1 digits)
  9. printf ("% ' #10s", $num); # # #100.001
  10. printf ("% ' @10s", $num); @@@100.001
  11. printf ("% ' _10s", $num); ___100.001
  12. printf ("% ' #-10s", $num); 100.001###
  13. printf ("% ' @-10s", $num); 100.001@@@
  14. printf ("% ' _-10s", $num); 100.001___
  15. printf ("% ' #20s", $num); ############ #100.001
  16. ?>

PHP Print function 5 sprintf ();

This cannot be output directly, first assigning a variable, and then outputting the variable.

 
  
  
  1. < ? PHP
  2. $ Num = - . 001;
  3. $ a = sprintf ("%d", $num);
  4. echo $a; 100
  5. ?>

PHP Print function 6 print_r ();

Function: Used only for output arrays.

PHP Print function 7 var_dump ();

Function: Output variable content, type, or string content, type, length. Commonly used to debug.

 
  
  
  1. < ? PHP
  2. $ a = - ;
  3. Var_dump ($a); Int (3) 100
  4. ?>


http://www.bkjia.com/PHPjc/446291.html www.bkjia.com true http://www.bkjia.com/PHPjc/446291.html techarticle in PHP print function 1 echo () can output multiple strings at the same time, can be multiple parameters, do not need parentheses, no return value. PHP Printing function 2 print () can only output one string at a time ...

  • 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.