zoukankan      html  css  js  c++  java
  • php方法工具函数合集(2020年10月7日)

    php 工具类
    1 php 生成唯一requestid 类 【v>7.1】
    2 php生成带logo二维码
    3 php 基于redis使用令牌桶算法实现流量控制
    5 php好用的组件列表
    1 请求,时间格式化,压缩,ftp 扩展包

    1)获取数组维度

    function arrayLevel ($arr ){  $al = array( 0 );
      $this -> aL( $arr ,$al );
      return max ($al );}

    function aL ($arr , &$al , $level= 0 ){
    if ( is_array( $arr )){
    $level ++ ;
    $al [] = $level ;
    foreach ( $arr as $v ){
    $this-> aL ($v , $al, $level );}}}

    2)在任一指定的键值后插入元素

    function insertAnyelement ($arr , $key, $varr ){
      $keys = array_keys( $arr );
      $kindex = array_search( $key ,$keys );
      $arr1 = array_slice( $arr ,0 ,( $kindex+ 1 ));
      $arr2 = array_slice( $arr ,($kindex + 1));
      $rs= array_merge ($arr1 , $varr, $arr2 );
      return $rs ;}

    3)截取中文字符串

    function chinesesubstr($str,$start,$len){
            $strlen=$start+$len;
            for($i=0;$i<$strlen;$i++){
                if(ord(substr($str,$i,1))>0xa0){
                    $tmpstr.=substr($str,$i,2);                $i++;
                }else{                $tmpstr.=substr($str,$i,1);            }
                return $tmpstr;        }    }

    4)去除文本中的html代码

    function cutstr_html($string, $sublen)   
     {  $string = strip_tags($string);
      $string = preg_replace ('/ /is', '', $string);
      $string = preg_replace ('/ | /is', '', $string);
      $string = preg_replace ('/&nbsp;/is', '', $string);
     
      preg_match_all("/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xbf]|[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/", $string, $t_string);   
      if(count($t_string[0]) - 0 > $sublen) $string = join('', array_slice($t_string[0], 0, $sublen).'...');   
      else $string = join('', array_slice($t_string[0], 0, $sublen)); 
      return $string; }

    5) 生成随机码及加密函数

    function password($password)
    {  /**后续整强有力的加密函数*/
      return md5('Q' . $password . 'W');}
    $token = password(uniqid(rand(), true));
    $salt = random(10);
    $identifier = password($user['uid'] . md5($user['user'] . $salt));
    $auth = $identifier . ',' . $token;

    判断数据的编码,同时转为统一的utf8 编码
    $encode = mb_detect_encoding(trim($v), array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
    $model[$k] = iconv($encode, 'utf-8', trim($v));
     
    获取中文汉字长度
    mb_strlen($name,"utf-8"); 【需开启php_mbstring扩展】

  • 相关阅读:
    HDU-1561
    POJ 1088
    UESTC-878
    CodeForces
    HDU 5753
    HDU 1568
    二分图入门题
    二分图匹配入门题
    树形dp入门
    UVA
  • 原文地址:https://www.cnblogs.com/sien6/p/13779536.html
Copyright © 2011-2022 走看看