备忘一些方法

1,获取用户首字母

/**
       * @name php获取中文字符拼音首字母
       * @param $str
       * @return null|string
       * @author 潘军伟<panjunwei@ruiec.cn>
       * @time 2015-09-14 17:58:14
       */
      public function getFirstCharter($str)
      {
        if (empty($str)) {
          return '';
        }
        $fchar = ord($str{0});
        if ($fchar >= ord('A') && $fchar <= ord('z')) return strtoupper($str{0});
        $s1 = iconv('UTF-8//IGNORE', 'GBK//IGNORE', $str);
        $s2 = iconv('GBK//IGNORE', 'UTF-8//IGNORE', $s1);
        $s = $s2 == $str ? $s1 : $str;
        $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
        if ($asc >= -20319 && $asc <= -20284) return 'A';
        if ($asc >= -20283 && $asc <= -19776) return 'B';
        if ($asc >= -19775 && $asc <= -19219) return 'C';
        if ($asc >= -19218 && $asc <= -18711) return 'D';
        if ($asc >= -18710 && $asc <= -18527) return 'E';
        if ($asc >= -18526 && $asc <= -18240) return 'F';
        if ($asc >= -18239 && $asc <= -17923) return 'G';
        if ($asc >= -17922 && $asc <= -17418) return 'H';
        if ($asc >= -17417 && $asc <= -16475) return 'J';
        if ($asc >= -16474 && $asc <= -16213) return 'K';
        if ($asc >= -16212 && $asc <= -15641) return 'L';
        if ($asc >= -15640 && $asc <= -15166) return 'M';
        if ($asc >= -15165 && $asc <= -14923) return 'N';
        if ($asc >= -14922 && $asc <= -14915) return 'O';
        if ($asc >= -14914 && $asc <= -14631) return 'P';
        if ($asc >= -14630 && $asc <= -14150) return 'Q';
        if ($asc >= -14149 && $asc <= -14091) return 'R';
        if ($asc >= -14090 && $asc <= -13319) return 'S';
        if ($asc >= -13318 && $asc <= -12839) return 'T';
        if ($asc >= -12838 && $asc <= -12557) return 'W';
        if ($asc >= -12556 && $asc <= -11848) return 'X';
        if ($asc >= -11847 && $asc <= -11056) return 'Y';
        if ($asc >= -11055 && $asc <= -10247) return 'Z';
        return null;
      }

2,过滤敏感词

/*
    * 过滤敏感词
    * $str
    * return $str
    */

   public function FilterWorde($str)
   {
       if ( !($words = file_get_contents( "../public/word/key.txt" )) ){
           die('file read error!');
       }
//     $word = preg_replace("/[1,2,3]\r\n|\r\n/i", '', $words);
       $arr = explode("|",$words);
       for($i=0;$i<count($arr);$i++)
       {
//         $str =  preg_replace('/'.$arr[$i].'/i', '***', $str);
           $str =  str_replace($arr[$i], '***', $str);

       }
       return $str;

   }

3,输入内容有表情,如昵称的解码和转码

/**
    把用户输入的文本转义(主要针对特殊符号和emoji表情)
     */
    function userTextEncode($str){
        if(!is_string($str))return $str;
        if(!$str || $str=='undefined')return '';

        $text = json_encode($str); //暴露出unicode
        $text = preg_replace_callback("/(\\\u[ed][0-9a-f]{3})/i",function($str){
            return addslashes($str[0]);
        },$text); //将emoji的unicode留下,其他不动,这里的正则比原答案增加了d,因为我发现我很多emoji实际上是\ud开头的,反而暂时没发现有\ue开头。
        return json_decode($text);
    }
    /**
    解码上面的转义
     */
    function userTextDecode($str){
        $text = json_encode($str); //暴露出unicode
        $text = preg_replace_callback('/\\\\\\\\/i',function($str){
            return '\\';
        },$text); //将两条斜杠变成一条,其他不动
        return json_decode($text);
    }

4,curl访问(包含https)

/**
     * 获取数据
     * @param $url
     * @param $data    post数组
     * @return mixed
     */
    public function getInfo($url,$data)
    {
        $ch = curl_init ();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt ( $ch, CURLOPT_URL, $url );
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
        $result = curl_exec ( $ch );
        curl_close ( $ch );
        return json_decode($result,true);
    }

/**
     * 获取数据
     * @param $url
     * @param $data    post数组
     * type  0 get  不传data参数  1 post
     * @return mixed
     */
    public function getInfo($url,$data,$type)
    {
        $ch = curl_init ();
        curl_setopt ( $ch, CURLOPT_URL, $url );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        if ($type)
        {
            curl_setopt ( $ch, CURLOPT_POST, 1 );
            curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
        }
        $result = curl_exec ( $ch );
        curl_close ( $ch );
        return json_decode($result,true);
    }

5,H5 js桥接交互

function setupWebViewJavascriptBridge(callback) {
        if (window.WebViewJavascriptBridge) {
            return callback(WebViewJavascriptBridge);
        }
        if (window.WVJBCallbacks) {
            return window.WVJBCallbacks.push(callback);
        }
        window.WVJBCallbacks = [callback];
        var WVJBIframe = document.createElement('iframe');
        WVJBIframe.style.display = 'none';
        WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
        document.documentElement.appendChild(WVJBIframe);
        setTimeout(function () {
            document.documentElement.removeChild(WVJBIframe)
        }, 0)
    }
    setupWebViewJavascriptBridge(function (bridge) {
        bridge.registerHandler('myron', function (data, response) {
            x = document.getElementById("kword");
            // x.innerHTML=data;
            response('success');
        });

 u = navigator.userAgent;
    isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
 //交互获取关键字
    function keyword(data) {
        var item = encodeURI(data);
        if (isiOS) {
            WebViewJavascriptBridge.callHandler('getKeyWord', {
                'key': item
            }, function responseCallback(responseData) {

            })
        } else {

            andrkey(data)

        }

    }
     function andrkey(data) {
        android.getKeyWord(data);
    }

6,查询添加链接

$mlMembers=Db::name('user_detail')
                    ->alias('ud')
                    ->join('mechanism_user mu','mu.mu_ub_id=ud.ud_ub_id')
                    ->field(["ud.ud_name",'ud.ud_ub_id','ud.ud_nickname','ud.ud_sex','concat("'.WEB_URL.'","",ud_photo)'=>'ud_photo','ud.ud_detail','mu.mu_type','mu.mu_ml_id'])
                    ->where('mu_ml_id',$ml_id)
                    ->where('mu_ub_id','<>',$ub_id)
                    ->select();

7,AJAX

 // $("#checkbill").click(function(){
     //     if (confirm('确认?')) 
     //     {
     //          var uf_id = $("#checkbill").attr('data');
        //              var postData = {
        //                     "uf_id": uf_id
        //             };
        //             $.post('{$Think.const.WEB_URL}/admin.php/user/test/test',
        //                 postData,
        //                 function(data) {
        //                     data = JSON.parse(data);
        //                     if(data != false) {
        //                         window.location.reload();
        //                     }else{
        //                         alert("操作失败");
        //                  }
        //                 }
        //             );
     //     }


     //        });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值