powerpoint2003 Official Download PHP learning output string echo,print,printf,print_r and Var_dump

Source: Internet
Author: User
Tags php programming
Here's a description.
1. Echo
echo is a keyword in PHP that has no return value. In the notation, it can omit parentheses. The following code:

Copy the Code code as follows:


Echo ' Test String ';
Echo (' Test String ');


2. Print
Print is also a keyword in PHP, it has a return value, generally returns true, the case should not return false. As with Echo, it is possible to omit the parentheses in the notation. The following code:

Copy the Code code as follows:


print ' Test String ';
Print (' Test String ');


3. printf
printf can format the output of a string like the C-language printf. It has the same format as the C language and is preceded by%. Its descriptor is defined as follows.
The b parameter is an integer that shows the binary
The c parameter is an integer that displays the corresponding ASCII character
The d parameter is an integer that displays its decimal
The f parameter is double and is displayed as a floating-point number
The e parameter is double precision and is shown as scientific counting type
The G parameter is double, displayed as a floating-point number or scientific counting type
The o parameter is an integer that shows its octal
The s parameter is a string, displayed as a string
The U parameter is an unsigned integer that displays its decimal
The x/x parameter is an integer that displays its hexadecimal (case-insensitive)
% output% to illustrate:
F,e default six digits after the decimal point, g in more than six digits (plus decimal), will be rounded, if the value after rounding is less than 1000000 will be directly output, greater than 1000000 will be displayed as scientific counting type. f The result of a value greater than 1.2e23 output is incorrect.
In addition to the above, the other can specify the total number of outputs (decimal point, E is one), and you can specify 0 or a space as a complement, you can also specify whether the complement is left or right.
F,e can specify the number of digits after the decimal point.
Such as%5d indicates that the total number of output is 5, insufficient left to fill the space,%05d indicates that the total output number is 5, insufficient left 0,%05.1f indicates the total output number is 5, insufficient left to fill 0, 1 digits after the decimal point,%-05.1f indicates the total output number is 5, insufficient right to fill 0, 1 digits after the decimal point;
Example code:

Copy the Code code as follows:


printf ("%7.2f", 1.2); "1.20"
printf ("%-07.2f", 1.2); "1.20000"


4. sprintf
sprintf and format conversion are like printf, the difference is that printf is output directly, and sprintf returns a formatted string.
5. Print_r and Var_dump
Both the Print_r and var_dump can output arrays and objects, but the output of the Print_r to the boolean is not obvious; the var_dump output is verbose and much more commonly used for debugging.
The following code:

Copy the Code code as follows:


$v = new test ();
Print_r ($v);
Var_dump ($v);
Class Test {
public $num = 1;
Public $str = "222";
Public $bln = true;


The result is:

Copy the Code code as follows:


Test Object
(
[num] = 1
[str] = 222
[BOOL] = 1
)
Object (Test) #1 (3) {
["Num"]=>
Int (1)
["Str"]=>
String (3) "222"
["BOOL"]=>
BOOL (TRUE)
}


Resources:
PHP Programming, 2003, fourth chapter string, output string

The above describes the powerpoint2003 official download PHP learning output string echo,print,printf,print_r and Var_dump, including the powerpoint2003 official download content, You want to be helpful to a friend who is interested in PHP tutorials.

  • Related Article

    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.