Home >Backend Development >PHP Tutorial >Single quotes within PHP double quotes

Single quotes within PHP double quotes

WBOY
WBOYOriginal
2016-08-08 09:26:031613browse

PHP will handle strings differently depending on whether the string is surrounded by single quotes or double quotes.

1. Single quote strings are considered raw text, and PHP will look for variables when processing double quote strings.

2. When quoting a single quote within a single quote, or quoting a double quote within a double quote, you need to add a transfer character, such as

' Mother's glasses ' and "his name is "jack" "

3. If there is no conflict in the quotation marks, there is no need to escape them, such as double quotation marks in single quotation marks, or Single quotes within double quotes, such as

“Mother's glasses” and ‘his name is "jack"

4. Single quotes only support the escape characters ' and \, and other escape characters can only be used in double quote strings.

PS: The above is the existing knowledge, and I wrote this blog post for the following example:

I never understood that single quotes are needed in VALUES in that sql statement, but the INSERT sentence does No, I understand now. It’s actually because this sql statement is written like this:

INSERT INTO email_list (first_name,last_name,email)
  VALUES ('string1','string2','string3')

That is, the values ​​in the brackets of VALUES must be enclosed in quotation marks, and $firstname in double quotation marks will be translated into Its own value, such as string1, Instead of saying what the single quotes do, in fact the single quotes inside are just regarded as part of the string .

The above introduces the single quotes in PHP double quotes, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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