Php string type description, php string description
PHP supports eight primitive types ).
Four scalar types:
Two composite types:
Two special types:
String type
A string is a string of characters, like "Hello world! ".
There are three methods to define a string:
1. Single quotes
Enclose a string with single quotes (') is the easiest way to define a string:
<? Php $ var_char = 'Code farming tutorial ';?>
If the string contains single quotation marks, escape using the backslash:
<? Php $ var_char = 'the string contains \' escape required '; echo $ var_char; // output: the string contains' escape required?>
Tip: If a backslash is required before single quotes or at the end of a string, two backslashes are required. In other words, the backslash only escapes the 'character here, but does not escape other characters.
If you only define a simple string without parsing more content, it is obviously more efficient to use single quotes.
2. Double quotation marks
If you use double quotation marks (") to define strings, PHP understands the escape sequence of more special characters:
Escape Sequence |
Description |
\ N |
Line feed |
\ R |
Enter |
\ T |
Horizontal Tab |
\ [/Td> |
Backslash |
\ $ |
Dollar sign |
\" |
Double quotation marks |
\ [0-7] {1, 3} |
This regular expression matches a character in the octal symbol. |
\ X [0-9A-Fa-f] {1, 2} |
This regular expression matches a character in the hexadecimal notation. |
Example:
<? Php $ var_char = "here is a line break \ n, which is the second line of text";?>
Note that the line feed in this example refers to the line feed in the Text Sense. to display the line feed in the browser, use the nl2br () function to replace \ n with <br/>.
The most important aspect of a double quotation mark string is that the variable name is replaced by the variable value parsing:
<? Php $ var_char = "this is some text"; echo "print these words: $ var_char"; // output: Please print these words: Is this some text?>
3. Definition of delimiters
The delimiter definition string uses the delimiter syntax (<), provides an identifier after the delimiter, then the defined string, and ends the string definition with the same identifier.
Example:
<? Php $ str = <EOD: An Example of defining strings with delimiters. This is more characters ...... EOD;?>
In this example, EOD is the identifier. The end identifier must start from the first column of the row. Similarly, the identifier must follow the naming rules for any other tag in PHP: it can only contain letters, numbers, underscores (_), and must start with an underscore or a non-digit character.
Note:The row where the end identifier is located cannot contain any other characters (except a semicolon;), including line indentation.
Tip:A string is not only a number of characters shown in the preceding example, but can also be defined as a string or even a huge long text, which is different from the char definition in the database.
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 the string into N parts and saves them to the array.
Php str_shuffle breaks the string and randomly arranges the characters of the string
The php str_rot13 () function obtains the ROT13 encoding of the string.
Php str_repeat () repeats the string N times