示例数组
$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;
}
}

被折叠的 条评论
为什么被折叠?



