/** * 邹颢 * zouhao619@gmail.com */** * Gets the current millisecond * @return string/function Get_millisecond () {$t = Explode (""
, Microtime ()); $t = $t [1].
($t [0] * 1000);
$t 2 = Explode (".", $t);
return $t 2 [0]; /** * Curl Simulate HTTP/HTTPS POST request * @param string $url request URL * @param array $data request parameter * @return string URL content/F
Unction curl_post ($url, $data =array ()) {$ch = Curl_init ($url); curl_setopt ($ch, curlopt_returntransfer,true); Get Data back to curl_setopt ($ch, curlopt_post,true);
When enabled, a regular post request is sent, with the type: application/x-www-form-urlencoded, just like the form submission. curl_setopt ($ch, Curlopt_postfields, $data); The POST operation in HTTP.
If you are transferring a file, you need a filename at the beginning of @ if (substr ($url, 0,5) = = ' https ') {curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
$content =curl_exec ($ch);
Curl_close ($ch);
return $content; /** * Curl Simulate HTTP GET request * @param string $url request URL * @param string|array $data Request parameter * @return String URL content * * fun
Ction Curl_get ($url, $data =array ()) {$url =rtrim ($url, '/'); if (!empty ($daTA)) {if (Is_array ($data)) {$first =true;
foreach ($data as $k => $v) {if ($first) {$url. = '? ';
$first =false;
}else{$url. = ' & ';
$url. = "{$k}={$v}";
}else{$data =ltrim ('? ', $data); $url. = '? '.
$data;
}} $ch = Curl_init ($url);
curl_setopt ($ch, Curlopt_header,false); curl_setopt ($ch, Curlopt_returntransfer, true);
Gets the data return if (substr ($url, 0,5) = = ' https ') {curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
} $content = Curl_exec ($ch);
Curl_close ($ch);
return $content; /** * Two-dimensional array key value sorting * @param array $arr two-dimensional array * @param string $keys key * @param string $type Ascending: ASC, descending: Desc (ELSE) *
@return Array */function Array_sort ($arr, $keys, $type = ' asc ') {$keysvalue = $new _array = Array ();
foreach ($arr 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] = $arr [$k];
return $new _array; }
/* * Get Client IP * @param number $type * @return string/function get_client_ip ($type = 0) {$type = $type? 1:
0;
static $IP = NULL;
if ($ip!== NULL) return $ip [$type];
if (Isset ($_server[' http_x_forwarded_for ')) {$arr = explode (', ', $_server[' http_x_forwarded_for ']);
$pos = Array_search (' unknown ', $arr);
if (false!== $pos) unset ($arr [$pos]);
$ip = Trim ($arr [0]);
}elseif (Isset ($_server[' http_client_ip ')) {$ip = $_server[' http_client_ip '];
}elseif (Isset ($_server[' remote_addr ')) {$ip = $_server[' remote_addr '];
}//IP address legal authentication $long = sprintf ("%u", Ip2long ($IP)); $ip = $long?
Array ($ip, $long): Array (' 0.0.0.0 ', 0);
return $ip [$type]; /** * Converts a string to a hump named * * @param string $str * @param boolean $big * True Big hump false Small hump * @return S
Tring */function Hump_type ($str, $big = False) {$str = Strtolower ($STR);
$big and Ucfirst ($STR); $str = Preg_replace ("/_" ([a-za-z])/e "," Strtoupper (' \\1') ", $str);
return $str; /** * Traverse Delete Folder * * @param string $path * Folder Address * @return Boolean/function Delete_files ($path) {if
_file ($path)) {return unlink ($path);
} if (Is_dir ($path)) {$handle = Opendir ($path); if ($handle!= false) {while (false!== ($file = Readdir ($handle))) {if In_array ($file, Array ('. ')
,
'..'
)) continue; $file = $path. '/' .
$file;
if (Is_dir ($file)) {delete_files ($file);
else if (Is_file ($file)) {if (unlink ($file) = = false) return false;
} closedir ($handle);
return true;
/** * intercept string (UTF8) * @param string $str * @param int $start * @param int $length * @param string $trim * @param string $charset * @return string/function sub ($str, $start, $lengt
H, $trim = "...", $charset = ' UTF-8 ') {$length +=2; if (function_exists (' Mb_get_info ')) {$iLenGth = Mb_strlen ($str, $charset);
$str = Mb_substr ($str, $start, $length, $charset);
if ($length < $iLength-$start) {$length-=2;
Return Mb_substr ($str, $start, $length, $charset). $trim;
}else{return $str; } else {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]/", $str, $info);
$str = Join ("", Array_slice ($info [0], $start, $length)); Return ($length < (sizeof ($info [0])-$start)? $str.
$trim: $str;
}/** * Browser friendly output * Wireless parameters/function dump () {$data =func_get_args ();
Ob_start ();
foreach ($data as $v) {var_dump ($v);
} $output = Ob_get_clean ();
if (! extension_loaded (' Xdebug ')) {$output = Preg_replace ('/\]\=\>\n (\s+)/M ', '] => ', $output); $output = ' <pre> '. Htmlspecialchars ($output, ent_quotes).
' </pre> ';
Echo ($output); }/** * FROMLeft query substring, find delete substring, delete only once * * @param string $str * @param string $find * @return string/function Subs
Tr_left_once ($str, $find) {$start = Strpos ($str, $find);
if (Is_bool ($start)) {return $str;
else {return substr ($str, $start + strlen ($find), strlen ($STR)); }/** * Queries the substring from the right, finds the substring, deletes only once * @param string $str * @param string $find * @return string/F
Unction substr_right_once ($str, $find) {$end = Strrpos ($str, $find);
if (Is_bool ($end)) {return $str;
else {return substr ($str, 0, $end); }
}