One, several PHP functions related to special character processing
Name of function |
Interpretation |
Introduced |
Htmlspecialchars |
Combine with, single double quotes, greater than, and less than sign into HTML format |
& Turn into & "Turn into " ' Turn into & #039; < turn into < > Turn into > |
Htmlentities () |
All characters are converted to HTML format |
In addition to the above Htmlspecialchars characters, the double-byte characters are displayed as encodings. |
|
|
|
Addslashes |
Single double quote, backslash, and null plus backslash escape |
The characters that are changed include single quotation marks ('), double quotation marks ("), backslash backslash (\), and null character null. |
Stripslashes |
Remove backslash characters |
Removes the backslash character from the string. If you have two consecutive backslashes, remove one and leave one. If there is only one backslash, remove it directly. |
|
|
|
Quotemeta |
Add Reference symbol |
The string that contains the. \\ + * ? [ ^ ] ($) to precede the character with the backslash "\" symbol. |
NL2BR () |
Turn newline characters into <br> |
|
Strip_tags |
Remove HTML and PHP tags |
Remove any HTML tags and PHP tags from the string, including the content between tags blocking. Note that if there is an error in the string HTML and PHP tags, an error will also be returned. |
Mysql_real_escape_string |
Escaping special characters in SQL strings |
Escaped \x00 \ r \ n space \ ' "\x1a, which is useful for multibyte character processing. Mysql_real_escape_string will judge the character set, mysql_escape_string do not consider it. |
For other string processing functions, refer to: Knowledge Sharing: PHP common string regular substitution and split function comparison.
PHP common Regular matching function between the differences, mainly Str_replace, Str_ireplace, Substr_replace, Preg_replace, Preg_match, Preg_match_all, Preg_quote, Preg_split, Ereg_replace, Eregi_replace, Preg_replace, Str_split, of course, a few of them can not use regular expressions, but because the relationship with the relevant regular function ambiguous so all put together to compare, convenient reference.
Name |
Support Regular |
Characteristics |
Note |
Str_replace |
X |
String substitution function, case sensitive |
|
Str_ireplace |
X |
String substitution function, case insensitive, array-type batch substitution support |
Thank netizens Franci, remind to add |
Substr_replace |
X |
Partial substitution string function, you can specify the position index |
|
|
|
|
|
Preg_replace |
Y |
Specifying a matching pattern for substitution, supporting substring references |
Priority use |
Ereg_replace |
Y |
Specify matching pattern for substitution, case sensitivity, support for substring references |
|
Eregi_replace |
Y |
Specifies that the matching pattern is replaced, case insensitive, and supports substring references |
|
|
|
|
|
Ereg |
Y |
Specifies the pattern full-text match, which can be used to match the judgment, or return a matching array |
|
Preg_match |
Y |
Specifies whether the pattern matches one exit, which can be used to match the judgment, or to use the returned matching array |
Priority use |
Preg_match_all |
Y |
Specifies a pattern full-text match, typically used to return a matching array |
Priority use |
|
|
|
|
Preg_split |
Y |
Specifies the regular split in the matching mode, if it is best to use explode or str_split |
|
Str_split |
X |
Specifies the length of the split string, by default a single character split into an array |
|
Explode |
X |
You can specify a single or multiple character splitting string, and a successful return array, for example, 12345 returns 12 and 5 according to the 34 split |
|
|
|
|
|
Preg_quote |
- |
Escape regular expression characters, meaning that special characters are prefixed with backslashes, and special characters for regular expressions include:. + * ? [ ^ ] $ ( ) { } = ! < > | : - |
|
|
|
|
|
Additional notes:
1, there are two sets of regular expression function library in PHP, the function is very similar:
The set is provided by the POSIX (portable Operating System Interface of Unix) library, which is named after the Ereg_ prefix and is no longer recommended for POSIX regular libraries.
The set is provided by the Pcre (Perl Compatible Regular Expression) library, which is named after the Preg_ prefix and is recommended for priority use. In Pcre, a pattern expression (that is, a regular expression) is typically included between two backslashes "/", such as the "/^w+$/" style.
2, PHP Regular expression function: matching extraction, matching replacement.
PHP filtering and processing of special characters for form submission