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.