27 Kwi 2016

Obliczanie różnicy czasu i obliczanie nowej daty

error_reporting(E_ALL ^ E_WARNING ^ E_PARSE ^ E_NOTICE);
//date_default_timezone_set ("PL/PL");
date_default_timezone_set ("Europe/Warsaw");

class date_check {
static public function check_on($data) {
$day_ts = 86400;

$date_order = $data['date_order'];
$roznica = (strtotime($date_order)-strtotime(date('Y-m-d')));

$roznica_day = floor($roznica/$day_ts);

echo $date_order."";
echo $roznica."";
echo $roznica_day."";

if($roznica_day<12) {

$date_start = date('Y-m-d', strtotime("1 day"));
$date_stop = date('Y-m-d', strtotime("21 day"));

} else {

$day_back = -10;
$day_next = 10;

$date_start = date('Y-m-d', strtotime($date_order." ".$day_back." day"));
$date_stop = date('Y-m-d', strtotime($date_order." ".$day_next." day"));
}

return array('date_start'=>$date_start, 'date_stop'=>$date_stop);
}
}

$data_back = date_check::check_on(array('date_order'=>'2016-04-18'));

echo $data_back['date_start']."";
echo $data_back['date_stop']."";

$data_back = date_check::check_on(array('date_order'=>'2016-04-11'));

echo $data_back['date_start']."";
echo $data_back['date_stop']."";

$data_back = date_check::check_on(array('date_order'=>'2016-04-26'));

echo $data_back['date_start']."";
echo $data_back['date_stop']."";

Wynik działania:

2016-04-18
-777600
-9
2016-04-28
2016-05-18

2016-04-11
-1382400
-16
2016-04-28
2016-05-18

2016-04-26
-86400
-1
2016-04-28
2016-05-18

24 lt. 2016

Parsowanie adresu uri strony

$urls = array (
'http://kody.wig.pl/file.php?key=9emixire&ampexpires=1456358400&amp;signature=76f289',
'http://kody.wig.pl/file.php?key=9emixire&expires=1456358400&signature=76f289');
$arr_url = parse_url($urls[0]);
parse_str($arr_url['query'], $arr_query);
print_r($arr_url);
print_r($arr_query);

Wynik:

Array
(
[scheme] =&gt; http
[host] =&gt; kody.wig.pl
[path] =&gt; /file.php
[query] =&gt; key=9emixire&amp;expires=1456358400&amp;signature=76f289
)
Array
(
[key] =&gt; 9emixire
[expires] =&gt; 1456358400
[signature] =&gt; 76f289
)