Home  >  Article  >  Backend Development  >  What is php escaping and escaping string data?

What is php escaping and escaping string data?

伊谢尔伦
伊谢尔伦Original
2017-04-12 09:35:192301browse

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#.

##Escape character codeThe meaning of escape character\ "Double quotes\ 'Single quotes\ \Backslash\ nLine break\ r Carriage return character\ tTab character\ $Dollar signNote: If you want to represent a single quote in a string, you need to use a backslash (\
) to escape it. For example, to represent the string "I'am", it needs to be written in this style "I\'am".

Example of using the transfer character " \ " to escape a string:

<?php
  echo &#39;this url_name = \&#39;PHP中文网\&#39;&#39;;
?>
The output result is:
this url_name = &#39;PHP中文网&#39;

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn