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; }
  • 相关阅读:
    CShop Project 082: 获取分页数据模型并传递到页面上
    CShop Project 08: 展示不同类型的商品
    CShop Project 08: 开发商品分类的查询和展示
    119 类和数据类型
    118 对象的绑定方法
    117 对象的属性查找顺序
    116 定制对象独有特征
    115 类和对象
    114 面向对象编程介绍
    113 面向对象程序设计的由来(了解)
  • 原文地址:https://www.cnblogs.com/suxiaolong/p/6053594.html
Copyright © 2011-2022 走看看