The difference between single and double quotes in php, the difference between double quotes in php_PHP tutorial

WBOY
Release: 2016-07-13 10:05:44
Original
912 people have browsed it

The difference between single and double quotes in php, the difference between double quotes in php

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

But the same type of single or double quotes must be used to define the string, such as: 'Hello World" and "Hello World' are illegal string definitions.

What is the difference between single quotes and double quotes?

PHP allows us to include 字串变量 directly in a double quote string.

The content in single quotation marks is always considered as ordinary characters, so the content in single quotation marks will not be escaped, which is more efficient.

For example:

<span>$str='hello';
echo "str is $str"; //运行结果: str is hello
echo 'str is $str'; //运行结果: str is $str</span><br /><br /><span>php中,双引号中的变量($var)和特殊字符(\r\n之类)会被转义,单引号中的内容不会被转义(所以效率更高)。</span><br /><span>使用上的话,</span><br /><span>我以前很喜欢在sql字符串里这样写$sql = "SELECT * FROM table WHERE id = $id",这样里面的$id可以被转义,单引号就不行。</span><br /><br /><span>在JavaScript中 单引号 和双引号没有区别,只要成对使用就行。<br />我在JavaScript 中使用单引号大多是因为 Javascript 和 HTML 打交道比较多,输出 HTML 片段的时候不需要转义 HTML 中属性的引号。<br />总之,看实际情况来用啦,怎么方便怎么使用。<br /></span><br /><br /><br /><br /><br />
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/962878.htmlTechArticlephp The difference between single and double quotes, the difference between php double quotes In PHP, English single quotes can be used to define strings ' ', you can also use English double quotes " ". But you must use the same type or...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!