首页 » PHP » 函数库 » 阅读文章

PHP函数用于清理用户输入

2013-10-15 13:48 7099 0 发表评论

<?php
function cleanInput($input) {

$search = array(
‘@<script[^>]*?>.*?</script>@si’, // Strip out javascript
‘@<[\/\!]*?[^<>]*?>@si’, // Strip out HTML tags
‘@<style[^>]*?>.*?</style>@siU’, // Strip style tags properly
‘@<![\s\S]*?–[ \t\n\r]*>@’ // Strip multi-line comments
);

$output = preg_replace($search, ”, $input);
return $output;
}
?>
<?php
function sanitize($input) {
if (is_array($input)) {
foreach($input as $var=>$val) {
$output[$var] = sanitize($val);
}
}
else {
if (get_magic_quotes_gpc()) {
$input = stripslashes($input);
}
$input = cleanInput($input);
$output = mysql_real_escape_string($input);
}
return $output;
}
?>

本文地址:http://www.jwzzsw.com/archives/1586.html

文章作者:思悟
版权所有 © 转载时请以链接形式注明作者和原始出处!

评论 共0条 (RSS 2.0) 发表评论

  1. 暂无评论,快抢沙发吧。

发表评论

联系我 Contact Me

回到页首