首页 > Web开发 > 详细

thinkphp tp5 常用 functions

时间:2017-02-18 19:45:00      阅读:288      评论:0      收藏:0      [点我收藏+]

 

/**
 * 过滤转换入脚本
 * @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

原文:http://www.cnblogs.com/shaoing/p/6413839.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!