function flash(){window".$target.".location.href='$url';}setTimeout('flash()','" . intval($wait) * 500 . "');"; if (!is_string($msg)) { $msg = $msg ? "操作成功!" : "操作失败!"; } echo $str . $msg . "  正在跳转中....."; die(); } /** * 取得当前页地址 * @return mixed */ public static function self() { return $_SERVER['REQUEST_URI']; } /** * 调整url自动生成规则 * @param string $action * @param array $get * @param bool $mergeGet * @return string */ public static function getSiteUrl($action = '', Array $get = array(), $mergeGet = false) { $url = '/' . trim($action, '/'); if ($mergeGet) { $get = array_merge($_GET, $get); } if ($get) { $get = urldecode(http_build_query($get)); } if ($get) { $url .= '?' . $get; } return $url; } /** * 链接生成器 * @param $url * @param array $get * @param null $text * @param null $attributes * @return string */ public static function anchor($url, Array $get = array(), $text = null, $attributes = null) { $url = '/' . trim($url, "/") . '/?' . http_build_query($get); $text = strlen($text) <= 0 ? $url : $text; $string = "$text"; return $string; } /** * 简易分页函数 * @param string $url 跳转地址 * @param int $totalPage 总页数 * @param int $current 当前页 * @param int $records 总记录数 * @param int $displayCount 总共显示的页数 * @return string */ public static function pagination($url, $totalPage = 10, $current = 1, $records = 100, $displayCount = 10) { $current = ($current < $totalPage) ? $current : $totalPage; $current = ($current >= 1) ? $current : 1; $first = 1; $half = ceil($displayCount / 2); $end = $totalPage; $prev = $current - 1; $next = $current + 1; foreach ($_GET as $key => $value) { if($value === ''){ unset($_GET[$key]); } } $linkSum = "
  • 总数:$records
  • "; $linkFirst = '
  • ' . self::anchor($url, array_merge($_GET, array('page' => $first)), '«') . '
  • '; $linkPrev = '
  • ' . self::anchor($url, array_merge($_GET, array('page' => $prev)), '‹') . '
  • '; $linkNext = '
  • ' . self::anchor($url, array_merge($_GET, array('page' => $next)), '›') . '
  • '; $linkEnd = '
  • ' . self::anchor($url, array_merge($_GET, array('page' => $end)), '»') . '
  • '; if ($current <= $half) { $linkFirst = ''; $last = $displayCount; if ($last > $end) { $last = $end; } if ($current == 1) { $linkPrev = ''; } if ($current == $end) { $linkNext = ''; } } elseif ($current > ($end - $half) AND $current <= $end) { $first = $current - $half + 1; $last = $end; $linkEnd = ''; if ($current == $end) { $linkNext = ''; } } else { $first = $current - $half + 1; $last = $current + $half; } $string = null; for ($i = $first; $i <= $last; $i++) { if ($i == $current) { $string .= '
  • ' . self::anchor($url, array_merge($_GET, array('page' => $i)), "$i", "class='active'") . '
  • '; } else { $string .= '
  • ' . self::anchor($url, array_merge($_GET, array('page' => $i)), "$i") . '
  • '; } } return $linkSum . $linkFirst . $linkPrev . $string . $linkNext . $linkEnd; } /** * 下拉菜单生成器 * @param $list * @param $key * @param $text * @param null $attributes * @return null|string */ public static function loopOutputSelect($list, $key = '', $text = '', $attributes = null) { if (!is_array($list) OR empty($list)) { return null; } $string = null; foreach ($list as $k => $v) { $selected = null; if ($k == $key) { $selected = "selected='selected'"; } $string .= "\n"; } if (!empty($text)) { $string = ""; } return $string; } /** * 单选按钮生成器 * @param $list * @param $key * @param $text * @param null $attributes * @return null|string */ public static function loopOutputRadio($list, $key = '', $text = '', $attributes = null) { if (!is_array($list) OR empty($list)) { return null; } $i = 0; $string = null; foreach ($list as $k => $v) { $checked = null; if ($k == $key) { $checked = "checked='checked'"; } $string .= "\n"; $i++; } return $string; } /** * 多选框生成器 * @param $list * @param string $key * @param string $text * @param string $attributes * @param string $separator * @return bool|string */ public static function loopOutputCheckbox($list, $key = "", $text = '', $attributes = "", $separator = "\n") { if (!is_array($list) || empty($list)) { return false; } $string = ''; if (!is_array($key)) { $key = array($key); } foreach ($list as $k => $v) { $string .= " 8 ? intval($length) : 8; $arr = array(); $arr[] = self::getRandoms($length - 4); $arr[] = strtoupper(self::getRandoms(1, 'char')); $arr[] = strtolower(self::getRandoms(1, 'char')); $arr[] = mt_rand(0, 9); $special = '!@#$%^*()'; $arr[] = $special{mt_rand(0, 11)}; shuffle($arr); return implode('', $arr); } /** * 获取随机数 * * @param int $length * @param string $type (可选) * @return string */ public static function getRandoms($length = 4, $type = '') { $returnStr = ''; $pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ'; if ($type == 'char') { $start = 10; $end = 61; } elseif ($type == 'num') { $start = 0; $end = 9; } else { $start = 0; $end = 61; } for ($i = 0; $i < $length; $i++) { $returnStr .= $pattern{mt_rand($start, $end)}; // 生成php随机数 } return $returnStr; } }