Using PHP to filter the principle of malicious characters is very simple we just define the characters and then use the foreach traversal of the malicious word repertoires, using Strpost to detect whether the user submitted data in the malicious word repertoires characters can be instantiated.
Example 1, determining whether a character exists
The code is as follows |
Copy Code |
function Is_bad_chars ($STR) { $bad _chars = Array ("\", "'" ' "'", ' "', '/', ' * ', ', '), ' < ', ' > ', ' r '," T "," N ", ' $ ', ' (', ') ', '% ', ' + ', '? ', '; ', ' ^ ', ' # ', ': ', ', ', ', ' = ', ' | ', '-'); foreach ($bad _chars as $value) { if (Strpos ($str, $value)!== false) { return true; } } } |
According to the above example we can do a filter keyword instance
The code is as follows |
Copy Code |
function Outip ($IP) {//Exclude IP @ $txt = file_get_contents ("Ip/ip.txt"); $txtarr = Explode ("rn", Trim ($txt)); if (count ($txtarr) <0) { return false; } if (In_array ($ip, $txtarr)) { return true; }else{ return false; } } |
Ip.txt file is to put some words you want to filter, which is each word or word for a line
http://www.bkjia.com/PHPjc/632830.html www.bkjia.com true http://www.bkjia.com/PHPjc/632830.html techarticle using PHP to filter the principle of malicious characters is very simple, we just define the characters and then use the foreach traversal of the malicious word repertoires, using Strpost to detect whether the user submitted data in the malicious word repertoires ...