Concepts and usage of PHP function echo

Source: Internet
Author: User

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.

 
 
  1. php $color = "red"; ?>
  2.  <p>Roses are 
  3. =$color?>
  4. p>
  5.  body> 
  6. html> 

1. echo output scalar

 
 
  1. Php
  2. Echo 123adb; // The output is correct.
  3. Echo 123abd; // correct
  4. Echo "123adb"; // correct
  5. ?>

2. PHP function echo () output variable, constant

 
 
  1. Php
  2. $ A = "123456 ";
  3. Echo $ a; // correct
  4. Echo "br> ";
  5. Echo "$ a"; // correct
  6. Echo "br> ";
  7. Echo $ a; // incorrect
  8. Echo "br> ";
  9. 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.
  10. Echo "br> ";
  11. // 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.
  12. Echo "br> ";
  13. $ B = 10;
  14. Echo $ B + 10; // display 20
  15. Echo "br> ";
  16. Echo "$ B + 10 ";
  17. Echo "br> ";
  18. Echo "the result is:". "$ B"; // the two statements have the same effect.
  19. Echo "br> ";
  20. Echo "Result: $ B"; // the two statements have the same effect.
  21. ?>

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.

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.