PHP String type explanation, PHP string explanation
PHP supports eight primitive types (type).
Four types of scalar:
Two kinds of composite types:
Two special types:
String type
A string is a sequence of characters, just like "Hello world!".
There are 3 ways to define a string:
1. Single quotation mark definition
Enclosing a string in single quotation marks (') is the simplest way to define a string:
If there is a single quotation mark in the string, you need to escape using a backslash (\):
Tip: If a backslash is required before the single quotation mark or at the end of the string, it needs to be represented by two backslashes. In other words, the backslash escapes only the ' character ' and does not escape other characters.
If you simply define a simple string without parsing more content, it is obviously more efficient to use single quotes.
2. Double quotation mark definition
If you define a string in double quotation marks ("), PHP knows more about the escape sequences of special characters:
Escape Sequences |
Description |
\ n |
Line break |
\ r |
Enter |
\ t |
Horizontal tab |
\[/td> |
Reverse Slash |
\$ |
Dollar sign |
\" |
Double quotes |
\[0-7]{1,3} |
This regular expression sequence matches a character represented by an octal symbol |
\x[0-9a-fa-f]{1,2} |
This regular expression sequence matches a character that is represented by a hexadecimal symbol |
Example:
Note that the line break in this example refers to the text meaning of line breaks, if you need to display a newline in the browser, you need to use the NL2BR () function to replace \ n
。
The most important point of a double-quote string is that the variable name is replaced by the value resolution of the variable:
3. Delimiter definition
The delimiter definition string is the delimiter syntax (<<<), and an identifier is provided after the delimiter, followed by the defined string, and finally the same identifier ending string definition.
Example:
In this example, EOD is the identifier. The end identifier must start at the first column of the row. Similarly, identifiers must follow the naming conventions of any other tag in PHP: They can only contain alphanumeric underscores, and must begin with an underscore or non-numeric character.
Note: the line where the end identifier is located cannot have any other characters (possibly except a semicolon; , including line indentation, and so on.
Hint: The string is not just a number of literal characters shown in the example above, but it can also be defined as a string, or even a large long text, which is not the same as the char definition in the database.
Original address: http://www.manongjc.com/php/php_string.html
Related reading:
PHP uses the Str_word_count () function to calculate the number of words in a string
PHP str_split () splits a string into n parts and saves it in an array
PHP Str_shuffle scrambled strings, randomly arranging characters of strings
PHP str_rot13 () function gets the ROT13 encoding of the string
PHP str_repeat () repeats the string n times
http://www.bkjia.com/PHPjc/1129317.html www.bkjia.com true http://www.bkjia.com/PHPjc/1129317.html techarticle PHP string type explanation, PHP string explanation PHP support eight primitive types (type). Four scalar types: Two composite types: two special types: string type one character ...