PHP Syntax single quotes, double quotes? Workaround

Source: Internet
Author: User
PHP Syntax single quotes, double quotes?
This post was last edited by u011523116 on 2013-08-01 20:12:13


a.php
print ' AAA '; Use single quotes, grammar pairs!
Echo ' BBB '; Use single quotes, grammar pairs!
?>



b.php
printf ' CCC '; Use single quotes, Error!
?>


1.a.php, two sentences are right, why?
PHP language, do not distinguish between single and double quotation marks?

2.b.php, this sentence is wrong, why?

Share to:


------Solution--------------------
1. The string can be wrapped in single-quote pairs or wrapped in double-quote pairs

2.printf is a function which is different from print and echo so be used with printf (' CCC ');


------Solution--------------------
1, in your example does not reflect the difference between single and double quotation marks, in PHP, in some cases the single/double quotation marks are still different.
2, a.php with print, and b.php is printf, two are different concepts.
The manual says:
Print is not actually a function (it's a language structure), so you don't have to use parentheses to enclose its argument list
And printf is a real function that needs to be enclosed in parentheses, so if you write in the second example: printf (' CCC '); That's right.
------Solution--------------------
The example of Xu big upstairs is very sharp.

PHP specifies that double quotation marks can contain either a string constant or a variable
The string that is stored in the variable is automatically exported at run time.

But if you use single quotes, no matter if the package does not contain a variable, it will output the pure string.
The reference to the Xu Big example can be very well understood
------Solution--------------------
This post was last edited by xuzuning on 2013-08-02 12:53:09

The language structure is a program block (process), the functional language does not have the equivalent component
You may be seen as a macro.
  • 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.