Home >Backend Development >PHP Tutorial >PHP determines whether there is a malicious character instance_PHP tutorial
The principle of using PHP to filter malicious characters is very simple. We only need to define the characters and then use foreach to traverse the malicious character library, and use strpost to detect whether there are any characters in the malicious character library in the data submitted by the user. Then we can instantiate it.
Example 1, determine whether a character exists
The code is as follows
|
Copy code
|
||||
$bad_chars = array("",' ',"'",'"','/','*',',','<','>',"r","t"," n",'$','(',')','%','+','?',';','^','#',':',' ','`', '=','|','-'); foreach($bad_chars as $value){ if (strpos($str,$value) !== false){ Return true; } } }
|
The code is as follows
|
Copy code |