首页 > 代码库 > thinkphp tp5 常用 functions

thinkphp tp5 常用 functions

 

/** * 过滤转换入脚本 * @param  $data * @param  $no_replace_key 不需要过滤转换的数据键 * @param string $request_type  请求类型 get post */function search_content_filter($data = array(), $request_type = ‘get‘, $no_replace_key = array()){    switch (strtolower($request_type)) {        case ‘get‘:            foreach ($data as $key=>$val) {                if(in_array($key, $no_replace_key)) {                    continue;                }                $_GET[$key] = trim(htmlspecialchars($val,ENT_QUOTES));            }            break;        case ‘post‘:            foreach ($data as $key=>$val) {                if(in_array($key, $no_replace_key)) {                    continue;                }                $_POST[$key] = trim(htmlspecialchars($val,ENT_QUOTES));            }            break;    }}//Utf 8 字符中文截取方法//截取utf8字符串function utf8Substr($str, $from, $len){    return preg_replace(‘#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,‘.$from.‘}‘.        ‘((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,‘.$len.‘}).*#s‘,        ‘$1‘,$str);}

 

thinkphp tp5 常用 functions