php 函数库

//对密码进行严格检查  至少含有规定个数的大写字母、小写字母、数字、特殊字符。
function check_password($password)
{
    # Checks that a password conforms to the configured paramaters.
    # Returns true if it does, or a descriptive string if it doesn't.
    global $lang, $password_min_length, $password_min_alpha, $password_min_uppercase, $password_min_numeric, $password_min_special;

    if (strlen($password) < $password_min_length) {
        return str_replace("?", $password_min_length, $lang["password_not_min_length"]);
    }

    $uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $alpha = $uppercase . "abcdefghijklmnopqrstuvwxyz";
    $numeric = "0123456789";

    $a = 0;
    $u = 0;
    $n = 0;
    $s = 0;
    for ($m = 0; $m < strlen($password); $m++) {
        $l = substr($password, $m, 1);
        if (strpos($uppercase, $l) !== false) {
            $u++;
        }

        if (strpos($alpha, $l) !== false) {
            $a++;
        } elseif (strpos($numeric, $l) !== false) {
            $n++;
        } else {
            $s++;
        } # Not alpha/numeric, must be a special char.
    }

    if ($a < $password_min_alpha) {
        return str_replace("?", $password_min_alpha, $lang["password_not_min_alpha"]);
    }
    if ($u < $password_min_uppercase) {
        return str_replace("?", $password_min_uppercase, $lang["password_not_min_uppercase"]);
    }
    if ($n < $password_min_numeric) {
        return str_replace("?", $password_min_numeric, $lang["password_not_min_numeric"]);
    }
    if ($s < $password_min_special) {
        return str_replace("?", $password_min_special, $lang["password_not_min_special"]);
    }


    return true;
}
 
function dump($vars, $label = '', $return = false) {
   if (ini_get('html_errors')) {
      $content = "<pre>\n";
      if ($label != '') {
         $content .= "<strong>{$label} :</strong>\n";
      }
      $content .= htmlspecialchars(print_r($vars, true));
      $content .= "\n</pre>\n";
   } else {
      $content = $label . " :\n" . print_r($vars, true);
   }
   if ($return) { return $content; }
   echo $content;
   return null;
}
function dump($var, $echo=true, $label=null, $strict=true) {
   $label = ($label === null) ? '' : rtrim($label) . ' ';
   if (!$strict) {
      if (ini_get('html_errors')) {
         $output = print_r($var, true);
         $output = "<pre>" . $label . htmlspecialchars($output, ENT_QUOTES) . "</pre>";
      } else {
         $output = $label . print_r($var, true);
      }
   } else {
      ob_start();
      var_dump($var);
      $output = ob_get_clean();
      if (!extension_loaded('xdebug')) {
         $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
         $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>';
      }
   }
   if ($echo) {
      echo($output);
      return null;
   }else
      return $output;
}

类似thinkPHP框架中dump函数
 
 
  1. /**
  2.  * 获取PDF文件页数的函数获取
  3.  * 文件应当对当前用户可读(linux下)
  4.  * @param  [string] $path [文件路径]
  5.  * @return [array]        [数组第一位表示成功与否,第二位表示提示信息]
  6.  */
  7.  function getPdfPages($path){
  8.     if(!file_exists($path)) return array(false,"文件\"{$path}\"不存在!");
  9.     if(!is_readable($path)) return array(false,"文件\"{$path}\"不可读!");
  10.     // 打开文件
  11.     $fp=@fopen($path,"r");
  12.     if (!$fp) {
  13.         return array(false,"打开文件\"{$path}\"失败");
  14.     }else {
  15.         $max=0;
  16.         while(!feof($fp)) {
  17.             $line = fgets($fp,255);
  18.             if (preg_match('/\/Count [0-9]+/', $line, $matches)){
  19.                 preg_match('/[0-9]+/',$matches[0], $matches2);
  20.                 if ($max<$matches2[0]) $max=$matches2[0];
  21.             }
  22.         }
  23.         fclose($fp);
  24.         // 返回页数
  25.         return array(true,$max);
  26.     }
  27.  }
  28.     /**
  29.      * 测试代码
  30.      */
  31.     $results=getPdfPages("demo.pdf");
  32.     if($results[0]){
  33.         // 在这里放置成功读取后的处理代码
  34.     }else{
  35.         // 在这里放置失败的处理代码
  36.     }
  37. https://github.com/Filiun/houhaibo/blob/master/function.php
  38. function dump($var, $echo = true, $label = NULL, $strict = true)
    {
    //    if (!defined('IS_TEST')) {
    //       return NULL;
    //    }
    
        $label = ($label === NULL ? '' : rtrim($label) . ' ');
    
        if (!$strict) {
            if (ini_get('html_errors')) {
                $output = print_r($var, true);
                $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>';
            }
            else {
                $output = $label . print_r($var, true);
            }
        }
        else {
            ob_start();
            var_dump($var);
            $output = ob_get_clean();
    
            if (!extension_loaded('xdebug')) {
                $output = preg_replace('/\\]\\=\\>\\n(\\s+)/m', '] => ', $output);
                $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>';
            }
        }
    
        if ($echo) {
            echo $output;
            return NULL;
        }
    
        return $output;
    }
    //判断是否是微信内置浏览器
    function is_weixin()
    {
       global $_W;
       if (($_W['uniaccount']['level'] == 1) || ($_W['uniaccount']['level'] == 3)) {
          return false;
       }
    
       if (empty($_SERVER['HTTP_USER_AGENT']) || ((strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows Phone') === false))) {
          return false;
       }
    
       return true;
    }





  39.  

                
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值