//对密码进行严格检查 至少含有规定个数的大写字母、小写字母、数字、特殊字符。
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函数
- /**
- * 获取PDF文件页数的函数获取
- * 文件应当对当前用户可读(linux下)
- * @param [string] $path [文件路径]
- * @return [array] [数组第一位表示成功与否,第二位表示提示信息]
- */
- function getPdfPages($path){
- if(!file_exists($path)) return array(false,"文件\"{$path}\"不存在!");
- if(!is_readable($path)) return array(false,"文件\"{$path}\"不可读!");
- // 打开文件
- $fp=@fopen($path,"r");
- if (!$fp) {
- return array(false,"打开文件\"{$path}\"失败");
- }else {
- $max=0;
- while(!feof($fp)) {
- $line = fgets($fp,255);
- if (preg_match('/\/Count [0-9]+/', $line, $matches)){
- preg_match('/[0-9]+/',$matches[0], $matches2);
- if ($max<$matches2[0]) $max=$matches2[0];
- }
- }
- fclose($fp);
- // 返回页数
- return array(true,$max);
- }
- }
- /**
- * 测试代码
- */
- $results=getPdfPages("demo.pdf");
- if($results[0]){
- // 在这里放置成功读取后的处理代码
- }else{
- // 在这里放置失败的处理代码
- }
- https://github.com/Filiun/houhaibo/blob/master/function.php
-
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;
}
-