php 批量过滤非法字符
<?php function testAddslashes($array) { if (!get_magic_quotes_gpc()) { if (is_array($array)) { foreach ($array as $key => $val) { $array[$key] = testAddslashes($val); } } else { $array = addslashes($array); } $array = str_replace("&#x", "& # x", $array); //过滤一些不安全字符s $array = str_replace("<", "<", $array); //过滤< } return $array; } if ($_POST) { print_r($_POST); echo '过滤前<hr /> '; $_POST = testAddslashes($_POST); echo '<hr />过滤后<br />'; echo $_POST['textfield']; } ?>
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> <label> <input type="text" name="textfield" /> </label> <p> <label> <input type="text" name="textfield2" /> </label> <label></label> </p> <p> <label> <input type="submit" name="Submit" value="提交" /> </label> </p> </form> </body> </html>
本文地址:http://www.phprm.com/code/f77083f8846727e6f933a9b7b162edfc.html
转载随意,但请附上文章地址:-)