The php learning knowledge introduced today is the string output function. There are four methods to transmit the output to the browser. The echo structure can output multiple values at a time, while print
The php learning knowledge introduced today is the string output function. There are four methods to transmit the output to the browser. The echo structure can output multiple values at a time, while print () only outputs one value. The printf () function inserts values into a template to create a formatted string. The print_r () function is useful for debugging. this function outputs arrays, objects, and other strings in forms that people can read more or less.
1. echo () function.
Echo is a language structure:
Echo "messi"; // no parentheses
Echo ("messi"); // You can also
Echo "messi", "barce", "best player"; // you can use commas to separate multiple output items.
2. print () function.
The print () function transfers a value (its parameter) to the browser. If the string is successfully displayed, true is returned. otherwise (for example, if the user presses the stop button of the browser at a certain time point in the page output), false is returned:
If (! Print ("hello, world "))
{
Die ("you're not listening to me !");
}
If the browser outputs normally, it outputs hello, world; otherwise, it outputs you're not listening to me !.
3. printf () function.
The printf () function inputs a string created by replacing the value into the template (format string. It is derived from functions of the same name in C language. The first parameter of printf () is a format string. The remaining parameters are the values that will be replaced. The character % in the format string indicates a replacement.
1. format modifier
Each replacement mark in the template is composed of a percent sign (%), which may be followed by the modifiers listed below, end with a type specifier (use '%' to get a single percent character in the output ).
2. type specifiers
The type specifier tells printf () what type of data will be replaced. This determines the robustness of the modifiers listed above. There are eight types, which are listed in the following table:
The B parameter is an integer and displayed as a binary number.
The c parameter is an integer and is displayed as a character corresponding to the value.
The d parameter is an integer and displayed as a decimal number.
The e or f parameter is a double-precision number and displayed as a floating point number.
The g parameter is a number with double precision and displayed as a floating point number.
The o parameter is an integer and displayed as an octal value (8-based ).
The s parameter is a string and displayed as a string.
The u parameter is an unsigned integer and displayed as a decimal number.
The x parameter is an integer and displayed as a hexadecimal number (based on 16). it must contain lowercase letters.
The X parameter is an integer and displayed as a hexadecimal number (based on 16), with uppercase letters