~~~ <?php namespace jqstu; class Jqutil { /** * @param $array * @param $keys * @param string $type * @return array */ public static function iarray_sort($array, $keys, $type='asc'){ $keysvalue = $new_array = array(); foreach ($array as $k => $v){ $keysvalue[$k] = $v[$keys]; } if($type == 'asc'){ asort($keysvalue); }else{ arsort($keysvalue); } reset($keysvalue); foreach ($keysvalue as $k => $v){ $new_array[$k] = $array[$k]; } return $new_array; } /** * @param $string * @param $find * @return bool */ public static function strexists($string, $find){ return !(strpos($string, $find) === FALSE); } /** * @param $length * @param bool $numeric * @return string */ public static function random($length, $numeric = FALSE){ $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35); $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed)); if ($numeric) { $hash = ''; } else { $hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64); $length--; } $max = strlen($seed) - 1; for ($i = 0; $i < $length; $i++) { $hash .= $seed{mt_rand(0, $max)}; } return $hash; } /** * @return string */ public static function getip(){ static $ip = ''; $ip = $_SERVER['REMOTE_ADDR']; if(isset($_SERVER['HTTP_CDN_SRC_IP'])) { $ip = $_SERVER['HTTP_CDN_SRC_IP']; } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) { foreach ($matches[0] AS $xip) { if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) { $ip = $xip; break; } } } if (preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $ip)) { return $ip; } else { return '127.0.0.1'; } } /** * @param string $message * @param int $code * @throws \Exception */ public static function JqException($message = "", $code = 0){ throw new \Exception($message,$code); } } ~~~