Today, I encountered a special character processing problem. I noticed this problem again in PHP:
* A PHP string with single quotes as the separator. Two escape characters/'and // are supported //
* A PHP string with double quotation marks as the delimiter. The following escape characters are supported:
/N line feed (LF or ASCII character 0x0a (10 ))
/R press enter (Cr or ASCII character 0x0d (13 ))
/T horizontal tab (HT or ASCII character 0x09 (9 ))
// Backslash
/$ Dollar sign
/"Double quotation marks
/[0-7] {1, 3} The regular expression sequence matches a character represented by the octal symbol
/X [0-9a-fa-f] {} This regular expression matches a sequence of characters represented by a hexadecimal symbol
For example:
An example with/0 special characters is as follows:
$ STR = "FFFF/0 ffff ";
Echo (strlen ($ Str ));
Echo ("/N ");
For ($ I = 0; $ I <strlen ($ Str); $ I ++) echo ("/t". ord ($ STR {$ I }));
Echo ("/N ");
Output result:
----------------------
9
102 102 102 102 0 102 102 102
Example of replacing special characters
$ STR = "FFFF/0 ffff ";
$ STR = str_replace ("/x0", "", $ Str );
// Or use $ STR = str_replace ("/0", "", $ Str );
// Or use $ 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 result:
----------------------
8
102 102 102 102 102 102 102
Octal ASCII code example:
// Note that the string that matches the regular expression/[0-7] {1, 3} represents an octal ASCII code.
$ STR = "/0/01/02/3/7/10/011/08/8"; // The/8 here does not meet the requirements, corrected to "// 8" (ASCII: 92 and 56)
Echo (strlen ($ Str ));
Echo ("/N ");
For ($ I = 0; $ I <strlen ($ Str); $ I ++) echo ("/t". ord ($ STR {$ I }));
Echo ("/N ");
Output result:
----------------------
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 result:
----------------------
10
0 1 2 3 7 8 9 16 17 255