zoukankan      html  css  js  c++  java
  • php 常用函数 util Memcached

    1.截取字符串
    function get_utf8_word($string, $length = 80, $more = 1, $etc = '..') {
        $strcut = '';
        $strLength = 0; //  /usd
        $width = 0;
        if (strlen($string) > $length) {
            //将$length换算成实际UTF8格式编码下字符串的长度
            for ($i = 0; $i < $length; $i++) {
                if ($strLength >= strlen($string)) {
                    break;
                }
                if ($width >= $length) {
                    break;
                }
                //当检测到一个中文字符时
                if (ord($string[$strLength]) > 127) {
                    $strLength += 3;
                    $width += 2;              //大概按一个汉字宽度相当于两个英文字符的宽度
                } else {
                    $strLength += 1;
                    $width += 1;
                }
            }
            return substr($string, 0, $strLength) . $etc;
        } else {
            return $string;
        }
    }
    
    
    mx_set_cache('_home_zs_course', $zs_course);

    $zs_course = mx_get_cache('_home_zs_course');


    /*
    * * @return Memcached */ function mx_get_memcached() { $connect = new Memcached; //声明一个新的memcached链接 $connect->setOption(Memcached::OPT_COMPRESSION, false); //关闭压缩功能 $connect->setOption(Memcached::OPT_BINARY_PROTOCOL, true); //使用binary二进制协议 $connect->addServer('ip...', 11211); //添加OCS实例地址及端口号 $connect->setSaslAuthData('f99d839f749911e4', '密码'); //设置OCS帐号密码进行鉴权 return $connect; } function mx_get_cache($key) { return null; $connect = mx_get_memcached(); $r = $connect->get($key); $connect->quit(); return $r; } function mx_set_cache($key, $value, $expire=36000) {return true; $connect = mx_get_memcached(); $r = $connect->set($key,$value,$expire); $connect->quit(); return $r; }
  • 相关阅读:
    1003 Emergency (25分)
    1013 Battle Over Cities (25分)
    1009 Product of Polynomials (25分)
    一元多项式的乘积与和(C++)
    1015 Reversible Primes (20分)
    list()函数对原来类型已经是列表的不会在添加[]
    全局变量把值固定
    python中None与Null的区别
    基础算法之排序
    列表和字符串的方法返回一个新的对象;直接加入到原对象中
  • 原文地址:https://www.cnblogs.com/suxiaolong/p/6053594.html
Copyright © 2011-2022 走看看