PHP Syntax single quotes, double quotes?

Source: Internet
Author: User
This post was last edited by u011523116 on 2013-08-01 20:12:13

a.php
 
  


 
  


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?


Reply to discussion (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 ');

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 ');

In C syntax, single and double quotes are two completely different concepts. Never mix!

In PHP syntax, do they appear to be the same?

PHP function is also very strange ah.

Some parts can be omitted,

such as: parentheses ().

I have encountered this kind of confusion before, especially when the query operation of database is combined, the single quotation mark and double quotation mark are more different.
I see a copy of the online information, linked to http://blog.csdn.net/wangjunhe/article/details/8191880,
The harvest is not small, you might as well see.

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.

$a = 123;echo "$a"; echo ' $a ';
I'll see.

In many cases, the computer language is not "why"
That's what you're designed for.

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

1.a.php, two sentences are right, why?
No, that's how it's designed, print and echo are language constructs, not functions.

PHP language, do not distinguish between single and double quotation marks?

Single quotes and double quotes are distinguished, single quotes are standard string data, and double quotes are special templates that can be task PHP because you can parse the contents of variables in double quotes

2.b.php, this sentence is wrong, why?
printf is a standard built-in function that is a function call without parentheses, and of course cannot execute

Other than that

$a = 123;echo "$a"; echo "
"Echo ' $a '; echo"
"echo" ' $a ' "; echo"
"Echo '" $a ";


Results

123
$a
' 123 '
"$a"

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.

Do you have an official handbook for this?
Give me a link!

PHP syntax is a single quotation mark and double quotation marks, the specific difference on the web there are many, anyway, there are pros and cons.
A.php in the Echo and print with single quotes do not go wrong, you can think: Echo, print is not a function, is an operator;
printf in b.php is a function that must be followed by parentheses.

1.a.php, two sentences are right, why?
No, that's how it's designed, print and echo are language constructs, not functions.

PHP language, do not distinguish between single and double quotation marks?

Single quotes and double quotes are distinguished, single quotes are standard string data, and double quotes are special templates that can be task PHP because you can parse the contents of variables in double quotes

2.b.php, this sentence is wrong, why?
printf is a standard built-in function that is a function call without parentheses, and of course cannot execute


Do you have an official manual (Chinese translation) in this area?


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.

Do you have an official handbook for this?
Give me a link!
http://php.net/manual/zh/function.print.php



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.

Do you have an official handbook for this?
Give me a link!
http://php.net/manual/zh/function.print.php

PHP language, "language structure" is a concept?
Does it have the same structure as the C language?

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.

Simply put, the language structure can be used either with parentheses or without parentheses.
The built-in function must be used with parentheses.

The output variable in PHP, or the direct output string, is typically using the Echo function:
Like what

$a = "

hello,world!


"Echo $a; echo" $a "; echo ' $a ';

The operating result is:

A variable with double quotation marks takes the variable out of the value first and then outputs it;
Change to that plus single quote will output the name of the variable directly;
printf functions are typically used to format strings
 
  

Output:
Hello World. Day Number 123
For a detailed usage of the printf function, you can look at:
Http://www.w3school.com.cn/php/func_string_printf.asp

Other than that

$a = 123;echo "$a"; echo "
"Echo ' $a '; echo"
"echo" ' $a ' "; echo"
"Echo '" $a ";


Results

123
$a
' 123 '
"$a"

echo "' $a '";

Above such statements, including multiple single or double quotation marks.
A web server that resolves such statements.
is the external symbol parsed first, or the internal symbol resolved first?
What is the parsing order?


Other than that

$a = 123;echo "$a"; echo "
"Echo ' $a '; echo"
"echo" ' $a ' "; echo"
"Echo '" $a ";


Results

123
$a
' 123 '
"$a"

echo "' $a '";

Above such statements, including multiple single or double quotation marks.
A web server that resolves such statements.
is the external symbol parsed first, or the internal symbol resolved first?
What is the parsing order?


In fact, this example just explains your problem.
Formally because the first parsing of the external, the last one, even if the interior is double quotation marks are still quoted as a string rather than a variable ....

Well, this is what I deduced from the results ... I don't know exactly.



Other than that

$a = 123;echo "$a"; echo "
"Echo ' $a '; echo"
"echo" ' $a ' "; echo"
"Echo '" $a ";


Results

123
$a
' 123 '
"$a"

echo "' $a '";

Above such statements, including multiple single or double quotation marks.
A web server that resolves such statements.
is the external symbol parsed first, or the internal symbol resolved first?
What is the parsing order?


In fact, this example just explains your problem.
Formally because the first parsing of the external, the last one, even if the interior is double quotation marks are still quoted as a string rather than a variable ....

Well, this is what I deduced from the results ... I don't know exactly.

PHP Official Handbook (Chinese translation) does this explain?

This is a study of the past thought not divided

Double quotes are escaped, and single quotes are not escaped.

  • 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.