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

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

王林
Release: 2023-03-04 12:46:01
Original
4716 people have browsed it

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template