Definition and usage of PHP function echo ()

Source: Internet
Author: User

In useDefinition 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. <html> <body> 
  2. php $color = "red"; ?>
  3.  <p>Roses are 
  4. =$color?>
  5. p>
  6.   body> 
  7. 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 the tip is included, 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.