Home > php教程 > PHP开发 > body text

PHP learning string output function

黄舟
Release: 2016-12-20 11:48:14
Original
1805 people have browsed it

The PHP learning knowledge introduced today is the output function of strings. There are four ways to send output to the browser. The echo structure can output multiple values ​​at once, while print() only outputs one value. The function printf() creates a formatted string by inserting values ​​into a template. The function print_r() is useful for debugging. It prints the contents of arrays, objects, and other strings in a more or less human-readable form.
1.echo() function.
Echo is a language structure:
echo "messi";//Without brackets
echo ("messi");//This is also possible
echo "messi","barce","best player";//You can use commas Split the specified output into multiple items
2.print() function.
The function print() sends a value (its parameter) to the browser. Returns true if the string is successfully displayed, otherwise (for example, at a certain moment when the page is output, the user pressed the browser's stop button) returns false:
                                                                                                                                                                                                                      can be returned. ("you're not listening to me!");
}
If the browser outputs normally, it will output hello, world, otherwise it will output you're not listening to me!.
3.printf() function.
The function printf() inputs a string established by replacing values ​​into the template (format string). It is derived from the function of the same name in the C language. The first parameter of printf() is the format string. The remaining parameters are the values ​​that will be substituted. The % character in the format string indicates a substitution.
1. Format modifiers
Each replacement tag in the template consists of a percent sign (%), which may be followed by the modifiers listed below, and ends with a type specifier (use '%%' in the output to get a single percent sign character).

2. Type specifier

The type specifier tells printf() what type of data will be replaced. This determines the robustness to the previously listed modifiers. There are eight types in total, we use the following table to list them:

          b   The parameter is an integer and displayed as a binary number
        c   The parameter is an integer and displayed as the character corresponding to the value
      d   The parameter is an integer and displayed as  A decimal number
      e or f The parameter is a double precision number and displayed as a floating point number
      g The parameter is a precision double number and displayed as a floating point number
        o The parameter is an integer and displayed as an octal number (8 is the base) number
s The parameter is a string and is displayed as a string
u The parameter is an unsigned integer and is displayed as a decimal number
x The parameter is an integer and is displayed as a hexadecimal (based on 16) Number, use lowercase letters
 Follow the PHP Chinese website (m.sbmmt.com)!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template