First of all, let’s talk about what are escape characters?
Escape characters are actually the specified PHP syntax used to output " \ ". However, the grammar stipulates that the functions of escape characters are different in different systems. For example: in the Windows system, the carriage return and line feed character is "\r" or "\n", while in the Linux system this There is a big difference between the two line breaks: "\r" means the cursor returns to the beginning of the line, but is still on the same line; "\n" means the next line and does not return to the beginning of the line.
The escape characters in PHP are as follows:
"\t"==>Horizontal tab## \\"==> Backslash
## " \' "== >Single quotation mark " \[0-7]{1,3} " Regular expression matches a character represented by octal notation
## " \x[0-9A-Fa-f]{1,2} " Regular expression matches a hexadecimal The characters represented by the symbol
In PHP, you can use the echo() and print() statements to send data to the web browser, and you can also use them to send HTML code to the web browser. Technically speaking. , echo() and print() are language constructs, not functions. A pair of parentheses are used here to help distinguish them from variables and other parts of PHP. There is essentially no difference between these two statements, so use that. None of them will cause any problems. It depends on personal preference..
Strings can use three methods: single quotes ('), double quotes ("), and delimiters (<<<) Definition. The best way to specify a string is to wrap it in single quotes ('). When using a string, it is likely that there are several characters in the string that are confused with PHP scripts. , so these characters need to be escaped. Use the escape character " \ "" in front of these characters.
" \ "is an escape. character, the first character immediately following "\" will become meaningless. For example, " ' " is the delimiter of a string and is written as " \' " loses the meaning of the delimiter and becomes an ordinary single quote " ' ". Friends can output a single quote through echo ' \' ' The quotes " ' ", but the escape characters " \ " are not displayed These characters have special meaning when used inside double quotes#.
\ " | |
\ ' | |
\ \ | |
\ n | |
\ r | |
\ t | |
\ $ | |
Example of using the transfer character " \ " to escape a string:
<?php echo 'this url_name = \'PHP中文网\''; ?>
this url_name = 'PHP中文网'
The above is the detailed content of What is php escaping and escaping string data?. For more information, please follow other related articles on the PHP Chinese website!