八、时间差异计算
- function ago($time)
- {
- $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
- $lengths = array("60","60","24","7","4.35","12","10");
-
- $now = time();
-
- $difference = $now - $time;
- $tense = "ago";
-
- for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
- $difference /= $lengths[$j];
- }
-
- $difference = round($difference);
-
- if($difference != 1) {
- $periods[$j].= "s";
- }
-
- return "$difference $periods[$j] 'ago' ";
- }
九、截取图片
- $filename= "test.jpg";
- list($w, $h, $type, $attr) = getimagesize($filename);
- $src_im = imagecreatefromjpeg($filename);
-
- $src_x = '0'; // begin x
- $src_y = '0'; // begin y
- $src_w = '100'; // width
- $src_h = '100'; // height
- $dst_x = '0'; // destination x
- $dst_y = '0'; // destination y
-
- $dst_im = imagecreatetruecolor($src_w, $src_h);
- $white = imagecolorallocate($dst_im, 255, 255, 255);
- imagefill($dst_im, 0, 0, $white);
-
- imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
-
- header("Content-type: image/png");
- imagepng($dst_im);
- imagedestroy($dst_im);
十、检查网站是否宕机
- function Visit($url){
- $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";$ch=curl_init();
- curl_setopt ($ch, CURLOPT_URL,$url );
- curl_setopt($ch, CURLOPT_USERAGENT, $agent);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch,CURLOPT_VERBOSE,false);
- curl_setopt($ch, CURLOPT_TIMEOUT, 5);
- curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch,CURLOPT_SSLVERSION,3);
- curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
- $page=curl_exec($ch);
- //echo curl_error($ch);
- $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- if($httpcode>=200 && $httpcode<300) return true;
- else return false;
- }
- if (Visit("http://www.google.com"))
- echo "Website OK"."n";
- else
- echo "Website DOWN";
(编辑:PHP编程网 - 黄冈站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|