输入过滤

//输入过滤 同时去除连续空白字符可参考扩展库的remove_xssfunction get_replace_input($str,$rptype=0){   $str = stripslashes($str);   $str = htmlspecialchars($str);   $str = get_replace_nb($str);   return addslashes($str);}//去除换行function get_replace_nr($str){   $str = str_replace(array("<nr/>","<rr/>"),array("\n","\r"),$str);   return trim($str);}//去除连续空格function get_replace_nb($str){   $str = str_replace("&nbsp;",‘ ‘,$str);   $str = str_replace(" ",‘ ‘,$str);   $str = ereg_replace("[\r\n\t ]{1,}",‘ ‘,$str);   return trim($str);}//去除所有标准的HTML代码function get_replace_html($str, $start=0, $length, $charset="utf-8", $suffix=false){   return myubstr(eregi_replace(‘<[^>]+>‘,‘‘,ereg_replace("[\r\n\t ]{1,}",‘ ‘,get_replace_nb($str))),$start,$length,$charset,$suffix);}
//生成字母前缀function get_letter($s0){   $firstchar_ord = ord(strtoupper($s0{0}));    if (($firstchar_ord>=65 and $firstchar_ord<=91)or($firstchar_ord>=48 and $firstchar_ord<=57)) return $s0{0};    $s = iconv("UTF-8","gb2312", $s0);    $asc = ord($s{0})*256+ord($s{1})-65536;    if($asc>=-20319 and $asc<=-20284)return "A";   if($asc>=-20283 and $asc<=-19776)return "B";   if($asc>=-19775 and $asc<=-19219)return "C";   if($asc>=-19218 and $asc<=-18711)return "D";   if($asc>=-18710 and $asc<=-18527)return "E";   if($asc>=-18526 and $asc<=-18240)return "F";   if($asc>=-18239 and $asc<=-17923)return "G";   if($asc>=-17922 and $asc<=-17418)return "H";   if($asc>=-17417 and $asc<=-16475)return "J";   if($asc>=-16474 and $asc<=-16213)return "K";   if($asc>=-16212 and $asc<=-15641)return "L";   if($asc>=-15640 and $asc<=-15166)return "M";   if($asc>=-15165 and $asc<=-14923)return "N";   if($asc>=-14922 and $asc<=-14915)return "O";   if($asc>=-14914 and $asc<=-14631)return "P";   if($asc>=-14630 and $asc<=-14150)return "Q";   if($asc>=-14149 and $asc<=-14091)return "R";   if($asc>=-14090 and $asc<=-13319)return "S";   if($asc>=-13318 and $asc<=-12839)return "T";   if($asc>=-12838 and $asc<=-12557)return "W";   if($asc>=-12556 and $asc<=-11848)return "X";   if($asc>=-11847 and $asc<=-11056)return "Y";   if($asc>=-11055 and $asc<=-10247)return "Z";   return 0;}

/** * [msubstr 截取字符串长度] * @param  [type]  $str     [description] * @param  integer $start   [description] * @param  [type]  $length  [description] * @param  string  $charset [description] * @param  boolean $suffix  [description] * @return [type]           [description] */function myubstr($str, $start=0, $length, $charset="utf-8", $suffix=true){   if(function_exists("mb_substr")){      $slice = mb_substr($str, $start, $length, $charset);   }elseif(function_exists(‘iconv_substr‘)) {      $slice = iconv_substr($str,$start,$length,$charset);      if(false === $slice) {         $slice = ‘‘;      }   }else{      $re[‘utf-8‘]   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";      $re[‘gb2312‘] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";      $re[‘gbk‘]    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";      $re[‘big5‘]   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";      preg_match_all($re[$charset], $str, $match);      $slice = join("",array_slice($match[0], $start, $length));   }   if(mb_strlen($str,‘utf8‘) > $length){      return $suffix ? $slice.‘...‘ : $slice;   }else{      return  $slice;   }}

/** * 单向 MD5 加密 */function encrypt($password) {   $password = md5($password.C(‘ENCRYPT_KEY‘));   $start = substr($password, 0,8);   $end   = substr($password, -8);   $password = $start . $end;   $password = md5($password);   return $password;}/** * 验证手机号 */function check_mobile($mobilephone){   //手机号码的正则验证   if(preg_match("/^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$|17[0-9]{1}[0-9]{8}$/",$mobilephone)){      return true;   }else{      return false;   }}/** * 验证QQ * @param unknown_type $qqstr */function check_qq($qqstr){   $qq_reg = ‘/^[1-9]{1}[0-9]{4,11}$/‘;   if (preg_match($qq_reg, $qqstr)){      return true;   }else{      return false;   }}/** * 验证固定电话 */function check_tel($tel){   $tel_pattern = ‘/^(0?(([1-9]\d)|([3-9]\d{2}))-?)?\d{7,8}$/‘;   if (preg_match($tel_pattern, $tel)){      return true;   }else{      return false;   }}/** * 验证邮箱 */function check_email($email){   $chars = "/^([a-z0-9+_]|\\-|\\.)[email protected](([a-z0-9_]|\\-)+\\.)+[a-z]{2,5}\$/i";   if (strpos($email, ‘@‘) !== false && strpos($email, ‘.‘) !== false){      if (preg_match($chars, $email)){         return true;      }else{         return false;      }   }else{      return false;   }}/** * [unique_arr 将二维数组中的重复值去除] * @param  [type]  $array2D  [description] * @param  boolean $stkeep   [description] * @param  boolean $ndformat [description] * @return [type]            [description] */function unique_arr($array2D,$stkeep=false,$ndformat=true){   // 判断是否保留一级数组键 (一级数组键可以为非数字)   if($stkeep) $stArr = array_keys($array2D);   // 判断是否保留二级数组键 (所有二级数组键必须相同)   if($ndformat) $ndArr = array_keys(end($array2D));   //降维,也可以用implode,将一维数组转换为用逗号连接的字符串   foreach ($array2D as $v){      $v = join(",",$v);      $temp[] = $v;   }   //去掉重复的字符串,也就是重复的一维数组   $temp = array_unique($temp);   //再将拆开的数组重新组装   foreach ($temp as $k => $v){      if($stkeep) $k = $stArr[$k];      if($ndformat)      {         $tempArr = explode(",",$v);         foreach($tempArr as $ndkey => $ndval) $output[$k][$ndArr[$ndkey]] = $ndval;      }      else $output[$k] = explode(",",$v);   }   return $output;}/** * [rebuild_array 将二维数组转成一维数组] * @param  [type] $arr [description] * @return [type]      [description] */function rebuild_array($arr){  //rebuild a array   static $tmp=array();   foreach($arr as $key=>$val){      if(is_array($val)){         rebuild_array($val);      }else{         $tmp[] = $val;      }   }   return $tmp;}/** * 获取浏览者ip * @param unknown_type $default * @return unknown */function GetRemoteIp($default=‘127.0.0.1‘){   $ip_string = $_SERVER[‘HTTP_CLIENT_IP‘].‘,‘.$_SERVER[‘HTTP_X_FORWARDED_FOR‘].‘,‘.$_SERVER[‘REMOTE_ADDR‘];   if ( preg_match ("/\d+\.\d+\.\d+\.\d+/", $ip_string, $matches) ) {      return $matches[0];   }   return $default;}
/** * 验证身份证号 */

function isCreditNo($vStr){   $vCity = array(         ‘11‘,‘12‘,‘13‘,‘14‘,‘15‘,‘21‘,‘22‘,         ‘23‘,‘31‘,‘32‘,‘33‘,‘34‘,‘35‘,‘36‘,         ‘37‘,‘41‘,‘42‘,‘43‘,‘44‘,‘45‘,‘46‘,         ‘50‘,‘51‘,‘52‘,‘53‘,‘54‘,‘61‘,‘62‘,         ‘63‘,‘64‘,‘65‘,‘71‘,‘81‘,‘82‘,‘91‘   );

if (!preg_match(‘/^([\d]{17}[xX\d]|[\d]{15})$/‘, $vStr)) return false;

if (!in_array(substr($vStr, 0, 2), $vCity)) return false;

$vStr = preg_replace(‘/[xX]$/i‘, ‘a‘, $vStr);   $vLength = strlen($vStr);

if ($vLength == 18)   {      $vBirthday = substr($vStr, 6, 4) . ‘-‘ . substr($vStr, 10, 2) . ‘-‘ . substr($vStr, 12, 2);   } else {      $vBirthday = ‘19‘ . substr($vStr, 6, 2) . ‘-‘ . substr($vStr, 8, 2) . ‘-‘ . substr($vStr, 10, 2);   }

if (date(‘Y-m-d‘, strtotime($vBirthday)) != $vBirthday) return false;   if ($vLength == 18)   {      $vSum = 0;

for ($i = 17 ; $i >= 0 ; $i--)      {      $vSubStr = substr($vStr, 17 - $i, 1);      $vSum += (pow(2, $i) % 11) * (($vSubStr == ‘a‘) ? 10 : intval($vSubStr , 11));      }

if($vSum % 11 != 1) return false;}

return true;}
时间: 2024-08-28 10:17:52

输入过滤的相关文章

如何实现select组件的选择输入过滤作用

实现select组件的选择输入过滤作用的js代码如下: /** *其中//******之间的部分显示的是在没有选择输入过滤功能的代码上加入的功能代码 ** / /** * @description This plugin allows you to make a select box editable like a text box while keeping it's select-option features * @description no stylesheets or images

Vanilla Masker – 功能强大的输入过滤插件

Vanilla Masker 是一个纯 JavaScript 实现的输入内容过滤和自动转换插件.现在你可以使用一个简单而纯粹的 JavaScript 库来控制你的 input 元素,而不需要加载 jQuery,Zepto 或者其它框架.不用担心兼容性,因为这是一个跨浏览器和跨设备的库. 您可能感兴趣的相关文章 Web 开发中很实用的10个效果[附源码下载] 精心挑选的优秀jQuery Ajax分页插件和教程 12款经典的白富美型 jQuery 图片轮播插件 让网站动起来!12款优秀的 jQuer

php关于输入过滤小结

Web的攻击,大部分是来自于外部,如Url上添加一些字段注入($_GET输入),表单的提交注入(一般为$_POST),所以在接收数据时对数据进行过滤,是很有必要的. 一.  一般php自带的过滤方法有: 1.空过滤 trim过滤字符串首尾空格 $name = trim($_POST['name']); 2.标签过滤 : strip_tags会将字符串中的php标签(<?php ?>)Html标签(<h1></h1><script></script>

input输入过滤js

html部分使用方式 <input  onkeyup="usrNameSet(this)" /> 其它的自己可以随便调用 Js部分 //只能输入数字.字母.小数点.汉字.@function usrNameSet(num){ var str=num.value;//var str = document.getElementById("userName").value; var value=str.replace(/[^\a-\z\A-\Z0-9\u4E00

PHP安全,防止SQL注入(输入过滤,输出转义)

(1)magic_quotes_gpc选项打开,在这种情况下所有的客户端GET和POST的数据都会自动进行addslashes处理 (2)防止对数字值的SQL注入,如用intval()等函数进行处理 (3)mysql_real_escape_string( string )  addslashes(string) 以上是利用PHP自带函数来防止SQL注入 下面提供一个例子,是在一个页面实现过滤,然后,需要用到的页面引入代码即可 #整站防注入 if (@magic_quotes_gpc()) {

javascript 键盘输入过滤,只能输入数字,小数一位且只能输入5

$("#right_div2 input[type='text'][class='textClass'][id^='asd_']").live("keydown",function(event) { var desValue = $(this).val()+event.char; if(event.keyCode>31 && event.keyCode != 128) { if(!/(^(\d+)$)|(^(\d+\.)$)|(^(\d+\.[

unity3d 5 InputField 非法路径文件名字符 输入过滤

转载请保留原文链接:http://blog.csdn.net/andyhebear/article/details/51361747 void Start() { if (this.Button == null) { this.Button = this.GetComponentInChildren<UI_ButtonClick>(); } if (this.InputText == null) { this.InputText = this.GetComponentInChildren<

输入、过滤和输出——PowerShell三分钟(八)

今天的三分钟给大家归纳一下PowerShell日常对数据的输入过滤和输出的处理 PowerShell输入数据的方式有很多种,包括直接输入字符.导入数据.捕获界面输入等 对于较少的信息,可以直接手工在PowerShell界面中输入: 这种方式很常见,对于需求信息较少的查询和操作非常方便 除此之外,还有Read-Host用于交互式输入: 由于是交互式输入,多用于必须用户干预的脚本 如果涉及到大量数据的输入,则需要用到Get-Content 首先准备一个txt,每一行都是需要输入的数据 通过Get-C

wireshark常用的过滤命令

我们使用wireshark抓包,却不知道如何分析这些包,也无法从海量的包中提取自己需要的数据,下面简单介绍下wireshark的过滤规则. 过滤源ip.目的ip.在wireshark的过滤规则框Filter中输入过滤条件.如查找目的地址为192.168.101.8的包,ip.dst==192.168.101.8:查找源地址为ip.src==1.1.1.1: 端口过滤.如过滤80端口,在Filter中输入,tcp.port==80,这条规则是把源端口和目的端口为80的都过滤出来.使用tcp.dst