Php syntax is divided into single quotes, double quotation marks?

Source: Internet
Author: User
Php syntax is divided into single quotes, double quotation marks? This post was last edited by u011523116 on 20:12:13

// A. php
 


 


1. a. php: both statements are correct. why?
Does the php language distinguish between single quotes and double quotes?

2. B. php: This statement is incorrect. why?


Reply to discussion (solution)

1. it is correct. strings can be enclosed in single quotes or double quotation marks.

2. printf is a function. this is different from print and echo. Therefore, printf ('CCC ') is used ');

1. it is correct. strings can be enclosed in single quotes or double quotation marks.

2. printf is a function. this is different from print and echo. Therefore, printf ('CCC ') is used ');

In the C syntax, single quotes and double quotes are two completely different concepts. You must never mix them!

In php syntax, they seem to be the same?

Php functions are also weird.

Some parts can be omitted,

For example, parentheses ().

I have encountered such questions before, especially when database query operations are combined, the difference between single quotes and double quotes is even greater.
I saw an online document with a link for http://blog.csdn.net/wangjunhe/article/details/8191880,
You may wish to take a look.

1. The difference between single quotes and double quotes is not shown in your example. in php, there are still differences between single quotes and double quotes.
2. print is used in a. php, while printf is used in B. php. The two are different concepts.
Manual description:
Print is actually not a function (it is a language structure), so you do not need to use parentheses to enclose its parameter list.
Printf is a real function and needs to be enclosed in parentheses. Therefore, if you write it in the second example: printf ('CCC ');

$a = 123;echo "$a";echo '$a';
Let's see.

In many cases, the computer language does not "why"
You have to do this.

The examples of upstairs xu are very sharp.

Php requires that double quotes can contain both string constants and variables.
The string stored in the variable is automatically output during running.

However, if single quotes are used, no matter the package does not contain variables, pure strings are output.
Refer to the example of xu for better understanding.

1. a. php: both statements are correct. why?
No, it is designed in this way. print and echo belong to the language structure, not a function.

Does the php language distinguish between single quotes and double quotes?

It distinguishes between single quotes and double quotes. single quotes are standard string data, while double quotes are special templates that allow tasks to be executed in php, because variable content in double quotes can be parsed.

2. B. php: This statement is incorrect. why?
Printf is a standard built-in function, and is a function call without parentheses. of course, it cannot be executed.

In addition

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


Result

123
$
'123'
"$"

1. The difference between single quotes and double quotes is not shown in your example. in php, there are still differences between single quotes and double quotes.
2. print is used in a. php, while printf is used in B. php. The two are different concepts.
Manual description:
Print is actually not a function (it is a language structure), so you do not need to use parentheses to enclose its parameter list.
Printf is a real function and needs to be enclosed in parentheses. Therefore, if you write it in the second example: printf ('CCC ');

Is there an official manual for this?
Give a link!

Php syntax is divided into single quotes and double quotes. There are many differences on the Internet, each of which has its own advantages and disadvantages.
Echo and print in a. php do not use single quotes. we can think that echo and print are actually not functions and are just operators;
Printf in B. php is a function and must be followed by parentheses.

1. a. php: both statements are correct. why?
No, it is designed in this way. print and echo belong to the language structure, not a function.

Does the php language distinguish between single quotes and double quotes?

It distinguishes between single quotes and double quotes. single quotes are standard string data, while double quotes are special templates that allow tasks to be executed in php, because variable content in double quotes can be parsed.

2. B. php: This statement is incorrect. why?
Printf is a standard built-in function, and is a function call without parentheses. of course, it cannot be executed.


Is there an official manual for this purpose (Chinese translation?


1. The difference between single quotes and double quotes is not shown in your example. in php, there are still differences between single quotes and double quotes.
2. print is used in a. php, while printf is used in B. php. The two are different concepts.
Manual description:
Print is actually not a function (it is a language structure), so you do not need to use parentheses to enclose its parameter list.
Printf is a real function and needs to be enclosed in parentheses. Therefore, if you write it in the second example: printf ('CCC ');

Is there an official manual for this?
Give a link!
Http://php.net/manual/zh/function.print.php



1. The difference between single quotes and double quotes is not shown in your example. in php, there are still differences between single quotes and double quotes.
2. print is used in a. php, while printf is used in B. php. The two are different concepts.
Manual description:
Print is actually not a function (it is a language structure), so you do not need to use parentheses to enclose its parameter list.
Printf is a real function and needs to be enclosed in parentheses. Therefore, if you write it in the second example: printf ('CCC ');

Is there an official manual for this?
Give a link!
Http://php.net/manual/zh/function.print.php

What is the concept of "language structure" in php?
Does it have the same structure as the C language?

This post was last edited by xuzuning at 12:53:09

The language structure is a program block (process), and functional languages have no equivalent components.
You may think of it as a macro.

To put it simply, the language structure can be included or used without parentheses.
Built-in functions must be enclosed in parentheses.

The echo function is generally used to output variables in php or directly output strings:
For example

$a="Hello,world!
";echo $a;echo "$a";echo '$a';

The running result is:

Adding double quotation marks to the variable will first take out the value and then output it;
The variable name will be directly output when the single quotation mark is added;
The printf function is generally used to format strings.
 

Output:
Hello world. Day number 123
For more information about the usage of the printf function, see:
Http://www.w3school.com.cn/php/func_string_printf.asp

In addition

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


Result

123
$
'123'
"$"

Echo "'$ '";

The preceding statements include multiple single quotes or double quotation marks.
The WEB server parses such statements.
Does it parse external symbols first or internal symbols first?
What is the resolution order?


In addition

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


Result

123
$
'123'
"$"

Echo "'$ '";

The preceding statements include multiple single quotes or double quotation marks.
The WEB server parses such statements.
Does it parse external symbols first or internal symbols first?
What is the resolution order?


In fact, this example illustrates your problem.
Because the external domain name is parsed first, the last domain name is resolved as a string, not a variable, even if it is a double quotation mark ....

Well, this is my inference based on the results... I don't know the accuracy.



In addition

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


Result

123
$
'123'
"$"

Echo "'$ '";

The preceding statements include multiple single quotes or double quotation marks.
The WEB server parses such statements.
Does it parse external symbols first or internal symbols first?
What is the resolution order?


In fact, this example illustrates your problem.
Because the external domain name is parsed first, the last domain name is resolved as a string, not a variable, even if it is a double quotation mark ....

Well, this is my inference based on the results... I don't know the accuracy.

Does the official php Manual (Chinese translation) provide this description?

I thought I did not know this.

The double quotation marks are escaped, and the single quotation marks 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.