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.