2016河北高考志愿填报指南小工具

2016-6-26 liyangweb.com 李杨 侃侃而谈

最近正赶上高考热,正好本人也看了点关于填报志愿的小技巧,其实很简单,但是如果让手动来计算,还是比较繁琐的,所以俺抽了一个晚上的时间,弄出来一个小程序,希望可以帮助一下不会填志愿的莘莘学子们。

链接http://zhiyuan.liyangweb.com/

阅读全文>>

评论(0) 浏览(1510)

windows下安装composer报错

2016-6-24 liyangweb.com 李杨 PHP

今天在windows下安装composer,遇到一个奇怪的问题:

在执行

php -r "readfile('https://getcomposer.org/installer');" | php
的时候,报了这样一个错误

阅读全文>>

标签: PHP

评论(0) 浏览(2452)

微信+yii2的那些坑

2016-6-15 liyangweb.com 李杨 PHP

最近搞了一个微信公众号玩,后台语言用的php7,选用yii2框架,在发开公众号自动回复的时候,遇到几点问题,下面我结合开发调试流程给大家讲解一下。
说明一下,关于具体如何一步一步的操作,微信官方以及网上都有很多现成的资料,故不是本文的重点,本文重点来帮广大开发人员填坑。

阅读全文>>

评论(3) 浏览(4742)

Facebook 样式的时间戳

2016-6-15 liyangweb.com 李杨 PHP

function nicetime($date)
{
    if(empty($date)) {
        return "No date provided";
    }

    $periods         = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
    $lengths         = array("60","60","24","7","4.35","12","10");

    $now             = time();
    $unix_date         = strtotime($date);

       // check validity of date
    if(empty($unix_date)) {    
        return "Bad date";
    }
    // is it future date or past date
    if($now > $unix_date) {    
        $difference     = $now - $unix_date;
        $tense         = "ago";

    } else {
        $difference     = $unix_date - $now;
        $tense         = "from now";
    }

    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] {$tense}";
}

$date = "2015-07-05 03:45";
$result = nicetime($date); // 2 days ago

评论(0) 浏览(1312)

计算两个地图坐标之间的距离

2016-6-15 liyangweb.com 李杨 PHP

function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
    $theta = $longitude1 - $longitude2;
    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $miles = acos($miles);
    $miles = rad2deg($miles);
    $miles = $miles * 60 * 1.1515;
    $feet = $miles * 5280;
    $yards = $feet / 3;
    $kilometers = $miles * 1.609344;
    $meters = $kilometers * 1000;
    return compact('miles','feet','yards','kilometers','meters'); 
}
$point1 = array('lat' => 40.770623, 'long' => -73.964367);
$point2 = array('lat' => 40.758224, 'long' => -73.917404);
$distance = getDistanceBetweenPointsNew($point1['lat'], $point1['long'], $point2['lat'], $point2['long']);
foreach ($distance as $unit => $value) {
    echo $unit.': '.number_format($value,4).'<br />';
}

评论(0) 浏览(1206)

把秒转换成天数,小时数和分钟

2016-6-15 liyangweb.com 李杨 PHP

function secsToStr($secs) {
    if($secs>=86400){$days=floor($secs/86400);$secs=$secs%86400;$r=$days.' day';if($days<>1){$r.='s';}if($secs>0){$r.=', ';}}
    if($secs>=3600){$hours=floor($secs/3600);$secs=$secs%3600;$r.=$hours.' hour';if($hours<>1){$r.='s';}if($secs>0){$r.=', ';}}
    if($secs>=60){$minutes=floor($secs/60);$secs=$secs%60;$r.=$minutes.' minute';if($minutes<>1){$r.='s';}if($secs>0){$r.=', ';}}
    $r.=$secs.' second';if($secs<>1){$r.='s';}
    return $r;
}

评论(0) 浏览(1753)

获取用户的真实IP

2016-6-15 liyangweb.com 李杨 PHP

function getRealIpAddr()  
{  
    if (!emptyempty($_SERVER['HTTP_CLIENT_IP']))  
    {  
        $ip=$_SERVER['HTTP_CLIENT_IP'];  
    }  
    elseif (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR']))  
    //to check ip is pass from proxy  
    {  
        $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];  
    }  
    else  
    {  
        $ip=$_SERVER['REMOTE_ADDR'];  
    }  
    return $ip;  
}

评论(0) 浏览(1158)

Powered by emlog 冀ICP备13011830号-1