Most of the time, we use echo. When using PHP for code editing, one or more strings are output normally, and the PHP function echo () is used (). The following describes how to use the PHP function echo.
Definition and usage
The PHP function echo () Outputs one or more strings.
Syntax
Echo (strings)
Parameter description
Strings is required. One or more strings to be sent to the output.
Tips and comments
Note: echo () is actually not a function, so you do not need to use parentheses for it. However, if you want to pass one or more parameters to echo (), a parsing error occurs when brackets are used.
Tip: The echo () function is a little faster than the print () function.
Tip: PHP function echo () can use simplified syntax. See the following example.
-
- php $color = "red"; ?>
- <p>Roses are
- =$color?>
- p>
- body>
- html>
1. echo output scalar
- Php
- Echo 123adb; // The output is correct.
- Echo 123abd; // correct
- Echo "123adb"; // correct
- ?>
2. PHP function echo () output variable, constant
- Php
- $ A = "123456 ";
- Echo $ a; // correct
- Echo "br> ";
- Echo "$ a"; // correct
- Echo "br> ";
- Echo $ a; // incorrect
- Echo "br> ";
- Echo abcdef; // It can be correctly displayed, but it is strongly not recommended to do so,
This is because many special characters cannot be correctly displayed.
- Echo "br> ";
- // Echo <abd>; // For example, if this is the case, it cannot be used,
You can go to the previous comment and try to see if it will return an error.
- Echo "br> ";
- $ B = 10;
- Echo $ B + 10; // display 20
- Echo "br> ";
- Echo "$ B + 10 ";
- Echo "br> ";
- Echo "the result is:". "$ B"; // the two statements have the same effect.
- Echo "br> ";
- Echo "Result: $ B"; // the two statements have the same effect.
- ?>
Echo "" is different from PHP function echo (). When double quotation marks are added, variables and specific symbols are escaped, the single quotation marks are output directly, so it is faster to use single quotation marks than to use double quotation marks. Do not use double quotation marks.