PHP Word Escape Considerations _php Tips

Source: Internet
Author: User
Tags ord
In php:

* PHP string with single quotation mark delimiter, support two escape \ ' and \
* A PHP string with double quotes as delimiters that supports the following escapes:
\ n line Wrap (LF or ASCII character 0x0A (10))
\ r Carriage return (CR or ASCII character 0x0D (13))
\ t Horizontal tab (HT or ASCII character 0x09 (9))
\ reverse Slash
\$ dollar Sign
\ "Double Quotes
\[0-7]{1,3} This regular expression sequence matches a character represented by a octal symbol
\x[0-9a-fa-f]{1,2} This regular expression sequence matches a character represented in hexadecimal notation

give a few examples:

An example that contains the special characters:

$str = "FFFF\0FFFF";
Echo (strlen ($STR));
Echo ("\ n");
For ($i =0 $i <strlen ($STR); $i + +) echo ("\ T". Ord ($str {$i}));
Echo ("\ n");

Output results:
----------------------

9
102 102 102 102 0 102 102 102 102

example of replacing special characters

$str = "FFFF\0FFFF";
$str = Str_replace ("\x0", "", $str);
or use $STR = Str_replace ("" "," ", $str);
or with $STR = Str_replace (chr (0), "", $str);
Echo (strlen ($STR));
Echo ("\ n");
For ($i =0 $i <strlen ($STR); $i + +) echo ("\ T". Ord ($str {$i}));
Echo ("\ n");
Output results:
----------------------
8
102 102 102 102 102 102 102 102


octal ASCII code example:

Note that the string that conforms to the regular \[0-7]{1,3} represents an octal ASCII code.
$str = "\0\01\02\3\7\10\011\08\8"; The \8 here are not compliant and are amended to "\\8" (ASCII is 92 and 56)
Echo (strlen ($STR));
Echo ("\ n");
For ($i =0 $i <strlen ($STR); $i + +) echo ("\ T". Ord ($str {$i}));
Echo ("\ n");
Output results:
----------------------
11
0 1 2 3 7 8 9 0 56 92 56

hexadecimal ASCII code example:

$str = "\x0\x1\x2\x3\x7\x8\x9\x10\x11\xff";
Echo (strlen ($STR));
Echo ("\ n");
For ($i =0 $i <strlen ($STR); $i + +) echo ("\ T". Ord ($str {$i}));
Echo ("\ n");
Output results:
----------------------
10
0 1 2 3 7 8 9 16 17 255
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.