How PHP strings are defined and their differences

Source: Internet
Author: User
This article mainly introduces the way of the definition of PHP string and their respective differences, has a certain reference value, now share to everyone, the need for friends can refer to

    • Single quotes:

Single quotation mark cannot parse variable

Single quotes cannot parse escape characters, only single quotes and backslashes themselves

Variables and variables, variables, and strings, strings, and strings can be used . Connection

    • Double quotes

Double quotation marks can parse variables, variables can use special characters and {} contain

Double quotes to resolve all escape characters

Variables and variables, variables, and strings, strings, and strings can be used . Connection

$sql = "SELECT * from user where name = ' {$name} '";-->select * from user where name = ' Lisi '

$sql = ' Select ' from user where name = \ '. $name. ' \''; Higher efficiency

    • The difference between single and double quotation marks

Single quote efficiency is higher than double quotation mark

    • Heredoc

Functions similar to double quotation marks

$str = <<<eodexample of stringspanning multiple linesusing heredoc syntax. EOD; $str = <<< "FOOBAR" Hello world! FOOBAR;

Cannot have any other symbols before the end identifier (indent is not allowed)

    • Nowdoc

Functions similar to single quotes

$str = <<< ' EOD ' Example of stringspanning multiple linesusing nowdoc syntax. EOD;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.