What is PHP escape and inverse literal string data?

Source: Internet
Author: User
first of all, what is an escape character?

The escape character, in fact, is the specified PHP syntax with "\" to output. However, the syntax of the rules in different systems to transfer the role of the character is different, for example: in the Windows System carriage return line character with "\ r" or "\ n", and in the Linux system, the two line breaks have a relatively large difference: "\ r" cursor back to the beginning, but still in the bank; "\ n" means the next line and does not go back to the beginning.

the escape characters in PHP are some of the following:

"\ n" ==> line break

"\ r" ==> carriage return

"\ t" ==> horizontal tab

"\ \" ==> backslash

"\$" ==> dollar sign

"\ '" ==> single quotation mark

"\" "==> double quotes

"\[0-7]{1,3}" regular expression matches the character represented by an octal symbol

"\x[0-9a-fa-f]{1,2}" regular expression matches the character represented by a hexadecimal symbol

In PHP, you can use the Echo () and print () statements to send data to a Web browser, or you can use them to send HTML code to a Web browser. Technically, Echo () and print () are language constructs, not functions, where a pair of parentheses is used to help separate the variables and other parts of PHP. The two statements are inherently no different, so using that one does not create any problems. It's a personal habit. They do not differentiate between size words.

The string can be defined using single quotation marks ('), double quotation marks ("), and a delimiter (<<<) 3 methods. The best way to specify a string is to wrap it up in single quotation marks ('). When using strings, it is likely that there are several characters in the string that are confused with PHP scripts, so you need to escape these characters by using the escape character "\"before these characters.

"\" is an escape character, and the first characters immediately after "\" become meaningless. such as "'" is the delimiter of the string, written as "\ " when it loses the meaning of the delimiter, into the ordinary single quotation mark "'" . Friends can output a single quote "'"via echo ' \ ', but the escape character "\" will not be displayed.

When you use these characters in double quotes, they have a special meaning

Escape character Codes Meaning of escape character
\ " Double quotes
\ ' Single quotation marks
\ \ Back slash
\ n Line break
\ r Carriage return character
\ t Tabs
\ $ Dollar sign

Description: If you want to represent single quotation marks in a string, you need to escape by using a backslash (\). For example, to represent the string "I am", you need to write this style "I\ ' am".

Use the transfer character "\" to escape the instance of the string:

<?php  echo ' This url_name = \ ' topic.alibabacloud.com\ ';? >

The output is:

This url_name = ' topic.alibabacloud.com '
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.