Function of single quotes and double quotation marks in PHP

Source: Internet
Author: User

String writing

Strings are enclosed in single, double, or inverted quotation marks with different meanings.
Single quotes
For example:
$ STR = 'An apple a day keeps the docter away .'
When the 'symbol appears in the string, the following must be added:
'I'm Wing'
Should be changed:
'I'm Wing'
, Where 'is called the Escape Character (Escape Character ).

Double quotation marks

PHP will perform the variable interpolation action on the string enclosed by double quotes, that is, replace the variable:
$ Name = "wing ";
Echo 'name: $ name ';
Echo "Name: $ name ";
The execution result is:
Name: $ name
Name: Wing
If the string in double quotation marks contains $ (dollar sign), you only need to change it to the escape character format:
$ Total = 12000
Echo "Total: $ total"; // output total: $12000
When performing variable interpolation, the variable name uses more than one space as the boundary. For example:
$ N_file = 5;
If ($ n_file = 1 ){
Echo "there are $ n_file .";
} Else {
Echo "there are $ n_files .";
}
When $ n_file is not set to 1, the variable "there are $ n_files." php sees is $ n_files, instead of the correct $ n_file, so it must be changed:
$ N_file = 5;
If ($ n_file = 1 ){
Echo "there are $ n_file .";
} Else {
Echo "there are {$ n_file} s .";
}

Double quotation marks in single quotation marks or single quotation marks in double quotation marks are regarded as valid characters and do not use escape characters. For example:
Echo "I'm a happy bird .";
Echo 'I'm a happy "bird "! ';
Output result:
I'm a happy bird.
I'm a happy "bird "!

Reverse quotation marks

You can run commands in UNIX using backquotes and return the execution results. For example:
Echo 'LS-L *. txt ';
Output the execution result of the LS-L *. txt command. The string enclosed by backquotes is the Unix command to be executed.

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.