武汉PHP培训
达内武汉民大中心

15271940953

热门课程

武汉PHP培训丨10个超级有用和最爱收藏的PHP代码样例(下)

  • 时间:2018-01-31 11:30
  • 发布:武汉PHP培训
  • 来源:互联网

    作为一个正常的程序员,会好几种语言是十分正常的,相信大部分程序员也都会编写几句PHP程序,如果是WEB程序员,PHP一定是必备的,即使你没用它开发过大型软件项目,也一定多少了解它的语法.
    六、通过Email显示用户的Gravatar头像
    $gravatar_link = 'http://www.gravatar.com/avatar/' . md5($comment_author_email) . '?s=32';
    echo '<img src="' . $gravatar_link . '" />';
    七、通过cURL获取RSS订阅数
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,'https://feedburner.google.com/api/awareness/1.0/GetFeedData?id=7qkrmib4r9rscbplq5qgadiiq4');
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
    $content = curl_exec($ch);
    $subscribers = get_match('/circulation="(.*)"/isU',$content);
    curl_close($ch);
    八、时间差异计算函数
    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);

武汉PHP培训

    $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";
    六、通过Email显示用户的Gravatar头像
    $gravatar_link = 'http://www.gravatar.com/avatar/' . md5($comment_author_email) . '?s=32';
    echo '<img src="' . $gravatar_link . '" />';
    七、通过cURL获取RSS订阅数
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,'https://feedburner.google.com/api/awareness/1.0/GetFeedData?id=7qkrmib4r9rscbplq5qgadiiq4');
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
    $content = curl_exec($ch);
    $subscribers = get_match('/circulation="(.*)"/isU',$content);
    curl_close($ch);
    八、时间差异计算函数
    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培训为您呈现,希望给您带来更多更好的文章,喜欢的朋友们可以添加微信公众号.

更多武汉PHP培训相关咨询,请扫描下方二维码

武汉PHP培训

上一篇:武汉PHP培训丨10个超级有用和最爱收藏的PHP代码样例(上)
下一篇:武汉PHP培训丨PHP要点!

能够提高PHP程序员效率的小妙招

想要学好PHP要怎么做

你学php准备做什么工作呢

PHP前景如何,现在学PHP还有前途吗?

选择城市和中心
贵州省

广西省

海南省