1.投票(获得票数总排名) 获取指定数据在数组中的排名 2.问卷调查过滤防注入 3.敏感词过滤

示例数组

$this->sortarray=array('21','1','3','13','8','4','3','12','4','8','9',);


获取指定数据在数组中的排名  or 获得票数总排名

//数据排名(数组去重,并按准许排序,再取值)
public function sortfirst(){
    //获取对应的key值
    $find = $this->input->get('value');
    //数组去重
    $stortun = array_unique($this->sortarray);
    //数组排序(函数排序)
    rsort($stortun);
    //判断查找数据是否存在数组中
    if(in_array($find,$stortun)){
        echo "对应排名:".intval(array_search($find,$stortun)+1);
    }else{
        echo "对应排名:".intval(count($stortun)+1);
    }
}

//数据排名(数组去重,并按准许排序,再取值)
public function sortsec(){
    //获取对应的key值
    $find = $this->input->get('value');
    //数组去重
    $stortun = array_unique($this->sortarray);
    //数组排序(函数排序)
    rsort($stortun);
    //数组key和value交换位置
    $sortarray = array_flip($stortun);
    //判断查找数据是否存在数组中
    if(in_array($find,$stortun)){
        echo "对应排名:".intval($sortarray[$find]+1);
    }else{
        echo "对应排名:".intval(count($stortun)+1);
    }
}

敏感词过滤(投票需要文字时关键词过滤)
function sencheck($list, $string){
    //违规词的个数
    $count = 0;
    //定义正则表达式
    $pattern = "/".implode("|",$list)."/i";
    //匹配到了结果
    if(preg_match_all($pattern, $string, $matches)){
        //匹配到的数组
        $patternList = $matches[0];
        $count = count($patternList);
    }
    //返回匹配结果
    if($count==0){
        return true;
    }else{
        return false;
    }
}

问卷调查过滤防注入

function check_str($str)
{
    $str = strtolower($str);
    $str = str_replace("'",'',str_replace('"','',$str));
    //结果返回
    if (substr_count($str,'select')>=1){
        return true;
    }elseif(substr_count($str,'update')>=1){
        return true;
    }elseif(substr_count($str,'delete')>=1){
        return true;
    }elseif(substr_count($str,'exec')>=1){
        return true;
    }elseif(substr_count($str,'count')>=1){
        return true;
    }elseif(substr_count($str,'if')>=1){
        return true;
    }elseif(substr_count($str,'ord')>=1){
        return true;
    }elseif(substr_count($str,'mid')>=1){
        return true;
    }elseif(substr_count($str,'cast')>=1){
        return true;
    }elseif(substr_count($str,'from')>=1){
        return true;
    }elseif(substr_count($str,'like')>=1){
        return true;
    }elseif(substr_count($str,'and')>=1){
        return true;
    }elseif(substr_count($str,'join')>=1){
        return true;
    }elseif(substr_count($str,'substring')>=1){
        return true;
    }elseif(substr_count($str,'database')>=1){
        return true;
    }elseif(substr_count($str,'substring')>=1){
        return true;
    }elseif(substr_count($str,'database')>=1){
        return true;
    }elseif(substr_count($str,'exp')>=1){
        return true;
    }else{
        return false;
    }
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值