Home  >  Article  >  Backend Development  >  What is the difference between single quotes and double quotes in php

What is the difference between single quotes and double quotes in php

王林
王林Original
2020-08-13 15:00:524639browse

The difference between single quotes and double quotes in php is: 1. Variables inside double quotes will be parsed, but not inside single quotes; 2. Variables and special characters in double quotes will be escaped. Content within single quotes will not be escaped.

What is the difference between single quotes and double quotes in php

In PHP, the definition of a string can use English single quotes ' ' or English double quotes " ".

(Recommended tutorial: php graphic tutorial)

Generally, the two are common, but the variables inside the double quotes will be parsed, but the single quotes will not be parsed.

PHP allows us to directly include string variables in double quotes, and the content in single quote strings is always considered to be ordinary characters, so the content in single quotes will not be escaped, which is more efficient.

(Video tutorial recommendation: php video tutorial)

For example:

$str='hello';
echo "str is $str"; //运行结果: str is hello
echo 'str is $str'; //运行结果: str is $str

In php, variables ($var) in double quotes and special Characters (such as \r\n) will be escaped, but the content in single quotes will not be escaped (so it is more efficient).

The above is the detailed content of What is the difference between single quotes and double quotes in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn