The application of double quotes and single quotes in PHP

Source: Internet
Author: User

Whether it's writing JavaScript or PHP, you're always used to using single quotes. But the weekend at home coding encountered a problem, you need to filter the string in the PHP line of characters, follow the following method:

$out = str_replace (Array (' RN ', ' r ', ' n '), ', $out); PHP provides three ways to define strings: single quotes, double quotes, and local documents (English is called here Document or Heredoc).

Single quotation mark:

Using single quotes is the most efficient method, because PHP does not check the built-in variables and escape sequences in the single quote string, and only the characters that need to be escaped are backslashes and single quotes themselves.

Double quotes:

Built-in variables and escape sequences are checked, but escaped single quotes are not recognized. This also illustrates the error of starting the code, and the right thing to do is to use double quotes to define the escape sequence for the newline:

$out = Str_replace (Array ("RN", "R", "N"), ", $out); Local document:

Check all built-in variables and escape sequences, and double quotes do not need to be escaped. For example:

Echo <<

This is a ' here document ' example.

Just for Test.

EOT, simple record, deepen the impression.

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.