


The difference between double quotes and single quotes in PHP (for newbies)_PHP Tutorial
Jul 13, 2016 pm 05:52 PM
Punctuation marks in programming languages are not like when we speak, we can add them casually and others will know what you want to say, but computers are different. Improper use will cause errors and cause you a lot of trouble. In PHP The use of single quotes and double quotes is a problem that novices often encounter. This article explains the difference between the two in detail. I hope it will be helpful to novices!
In PHP, a string is usually defined within a pair of quotation marks, such as:
'I am a string in single quotes'
"I am a string in double quotes"
The PHP parser uses pairs of quotation marks to determine a string. Therefore, all strings must use the same single or double
Quotation marks to define start and end. For example, the following string definition is illegal:
"I am not a valid string since I have unmatching quote marks'
'Me neither!"
When defining a string, only one kind of quotation mark is considered as the delimiter, that is, single quotation mark or double quotation mark. So, if a string is represented by a double quote
, then only double quotes are parsed by the parser. This way, you can include any other character within the double-quoted string, even single-quoted
Number. The following quotation mark strings are legal: www.2cto.com
$s = "I am a 'single qThe above example attempts to include double quotes within a double quote string, and the parser considers the string to be terminated when it encounters the second double quote
It’s over. To achieve the purpose of including quotation marks, the parser must ignore its original meaning when encountering ordinary quotation marks in the string. We use the quotation mark
Add a backslash in front of it to tell PHP that this quote is part of the string. The correct representation is like this:
"Why doesn't "that" work?"
A common problem in English strings is the use of apostrophe ', because it is a single quote, and it is very common in English strings
(English possessive case). You must be careful with these characters:
'You'd better escape your a post rophes'
You can see that backslash has its special meaning in the string. When we need to include the backslash itself in the string, we need to include it in
This symbol is preceded by an extra backslash. For example:
$file = "c: windows system.ini";
echo $file; // The print result is: c: windows system.ini
$file = "c:\windows\system.ini";
echo $file; // The print result is: c:windowssystem.ini
uote string' inside a double quote string";
$s = 'I am a "double quote string" inside a single quote string';
Author: Feiyu 1993

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

Does Bitcoin have stocks? Does Bitcoin have equity?

deepseek What is the difference between r1 and v3 version

How To Set Up Visual Studio Code (VS Code) for PHP Development

How do you parse and process HTML/XML in PHP?

PHP Program to Count Vowels in a String

What is the difference between pre-market and after-market trading? Detailed explanation of the differences between pre-market and after-market trading
