Strings are composed of a series of characters, in php, characters and bytes, that is, a total of 256 different characters of the possibility.
The string type can be defined in three ways: single-quote , double-quote , and heredoc-structured .
1, each instruction can remember to use ";" END;
2, the single quotation mark begins to end with a single quotation mark Oh, double quotation marks begin to end with double quotation marks;
3, remember that both single and double quotation marks are in English
I. What to do when a string contains quotation marks
Scenario One: Embedding double quotes in single quotes
Scenario Two: Embedding single quotation marks in double quotation marks
Scenario three: Using the escape character "\"
1, nested time single quotes hug double quotes Oh, double quotation marks in the embrace of single quotes Oh;
2, single quotes hug single quotes, double quotes hug double quotes, but need "\" escape character in the presence of OH;
3. Note that both single and double quotes are in English.
Two. What happens when quotation marks are met with a variable marked with a dollar sign
When a variable is enclosed in double quotes, the variable is concatenated with the contents of the double quotation mark;
When a variable is included in a single quotation mark, the variable is exported as a string.
:
<? $love = "I Love you!" $string 1 = "mu class net,$love"; $string 2 = ' mu class net. $love '; $string 3 = "$string 2"; Echo $string 1 ; Echo "<br/>"; Echo $string 2 ;? >
- The variable "$love" to be enclosed in quotation marks;
- Note the quotation marks in the code are quoted in the English state.
Three. What to do if the string is long
You can use the heredoc structure to solve the problem by first using the delimiter to represent the string (<<<), then providing an identifier after "<<<" GOD, then the string, End the string with the supplied identifier
After assigning the symbol, enter the delimiter "<<<", followed by the identifier, you can use your goddess as the identifier "GOD", such as line 2nd, you can also use your favorite dog, "dog" as an identifier, but at the end of the identifier must be the same. In addition, at the end of a line, such as the 7th line, must be another row, and this line except "GOD", and ";" After the end, there can be no other characters, before and after can not have, including spaces, otherwise it will appear wrong oh. Remember, remember.
Scalar Type-string (4)
What happens when my string is long?
We can solve this problem by using the heredoc structure form , first using the delimiter to represent the string (<<<), then providing an identifier after "<<<" GOD, then the string, Finally, the string is terminated with this identifier provided.
After assigning the symbol, enter the delimiter "<<<", followed by the identifier, you can use your goddess as the identifier "GOD", such as line 2nd, you can also use your favorite dog, "dog" as an identifier, but at the end of the identifier must be the same. In addition, at the end of a line, such as the 7th line, must be another row, and this line except "GOD", and ";" After the end, there can be no other characters, before and after can not have, including spaces, otherwise it will appear wrong oh. Remember, remember.
-
- Delimiters ("<<<") after identifiers must also follow the naming conventions of any other tag in PHP: Alphanumeric underscores only, and must begin with an underscore or non-numeric character;
- The Goddess at the end ("GOD") is waiting for you in a new line.
- Check if there are any spaces or other non-";" characters before and after the goddess ("GOD") at the end, and don't miss the ";"
String knowledge about PHP