This article mainly introduces the three kinds of expressions of strings in PHP, the Friends of interest, I hope to help you.
(1) using single quotation marks
The escape character in single quotation marks can only be: \ \, \ '
(2) Use double quotation marks
In double quotes, all escape characters can be used. such as: \ \, \ ', \ ', \$, \ n, \ r, \ t
(3) How to represent a long string
Long string representation, must be placed in "<<"<<"Heredoc;" Must be the end of the tag. Must be a single line and the head is written.
Heredoc can customize the name.
PHP variables can be parsed directly.
Considerations for Strings
1. Within double quotes, the output is the value of the variable. For example: Echo "{$name} is 24 years old"
2. Within single quotes, the output is the name of the variable, not the value.
3, in double quotation marks, if a variable name followed by a non-null character, it will make the compiler confused. The solution is that the following can be followed by a space, or with the English punctuation (special characters), which will parse the variables. The usual method is to add a brace, {$name}
<! DOCTYPE html> <HTML> <HEAD> <TITLE> New Document </TITLE> <meta name= "Generator" content= "EditPlus" > <meta name= "Author" content= "" > <meta name= "Keywords" content= " "> <meta name=" Description "content=" "> <style type=" Text/css "> </style> <script type= "Text/javascript" > </script> </HEAD> <BODY> <?php $name = "Zhang San"; $age =24; $str =<<
Related recommendations:
PHP long String definition method
How MySQL gets the value after a special character in a variable length string (from StackOverflow)
Example of a PHP long string (here Document) Definition method