The use of the Echo () function in PHP (with code)

Source: Internet
Author: User
Tags php language parse error
Sometimes when we use the PHP language to encode a situation where we can output one or more strings, what do we do when we encounter this situation? At this point we need to use the function echo () of PHP. Next, this article will talk about the use of the Echo () function in PHP. Take a look at the specific example of the Echo () function.

Definition and usage

The PHP function echo () outputs one or more strings.

Grammar

Echo (Strings)

Parameter description

Strings must have. One or more strings to send to the output.

Hints and Notes

Note: Echo () is not actually a function, but rather a language structure, so you do not need to use parentheses on it. However, if you want to pass one or more arguments to echo (), a parse error occurs when you use parentheses.

Tip: the Echo () function is a little faster than the print () function.

Tip: The PHP function echo () can use the simplified syntax. As shown in the following example:


1.echo Output Scalar

PHP   echo 123adb;//output correct    echo 123abd;//correct    echo "123adb";//correct  ?>

2, PHP function echo () output variable, constant

PHP $a = "123456";  echo $a;  Correct  echo "< span>br>";  echo "$a"; Correct  echo "< span>br>";  echo $a;//Incorrect  echo "< span>br>";  echo abcdef;  Can be displayed correctly, but it is strongly not recommended because there are many special symbols that do not display correctly.  echo "< span>br>";  Echo <abd>;  For example, with a pointed, you can not use, you may go to the front of the comments to try will not error.  echo "< span>br>";  $b =10;  echo $b +10; Display  echo "< span>br>";  echo "$b +10";  echo "< span>br>";  echo "The result is:". " $b "; The effect of these two formulations is the same.  echo "< span>br>";  echo "The result is: $b";  The effect of these two formulations is the same.  ?>

echo "" and the PHP function echo () are different, double quotation marks when the variable is escaped with a particular symbol, the addition of single quotation marks will not be escaped, the single quotation marks the direct output of the symbol, so that the single quotation marks than double quotation marks a little faster. Don't use double quotation marks when you can.

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.