This article introduces the filtering method of special characters when submitting data in a PHP form. Learn how PHP filters special characters and what character filtering functions are available. Friends in need can refer to it.
The method of processing special characters submitted by PHP forms mainly uses several functions such as htmlspecialchars/addslashes/stripslashes/strip_tags/mysql_real_escape_string. 1. PHP functions related to special character processing Function name Definition introduce htmlspecialchars Convert ampersands, single and double quotation marks, greater than and less than signs into html format &Turn into& "Turn into" ' Turn into' Convert> htmlentities() All characters are converted to html format In addition to the htmlspecialchars characters above, it also includes double-byte characters displayed as encodings, etc. addslashes Single and double quotes, backslashes and null plus backslash escaping The modified characters include single quotation mark ('), double quotation mark ("), backslash () and the null character. stripslashes Remove backslash characters Remove backslash characters from a string. If there are two consecutive backslashes, remove one and leave one. If there is only one backslash, just remove it. quotemeta Add quotation marks Add the backslash "" symbol in front of characters such as \ + * ? [ ^ ] ( $ ) in the string. nl2br() Convert newline characters to strip_tags Remove html and php tags Remove any html tags and php tags in the string, including the content between tag blocks. Note that if there are errors in the string html and php tags, errors will also be returned. mysql_real_escape_string Escape special characters in sql string Escape x00 n r space ' " x1a, which is very effective for multi-byte character processing. mysql_real_escape_string will determine the character set, but mysql_escape_string does not need to be considered. html special character filter php class How to escape special characters in url links Detailed explanation of php special character escaping php filter parameter special characters anti-injection php method to filter illegal and special strings php example: example of special character processing function php code to replace special characters in extra long text |