1 i f 2 <--- 해석가능하시죠 ?

Posted
Filed under dog발;/php
function cal_diff_date($date1, $date2)
{
	if(version_compare("5.3", phpversion(), "<="))
	{
		$date_1 = new DateTime($date1);
		$date_2 = new DateTime($date2);
		$date_diff = $date_1->diff($date_2);

		return array(
			"year" => $date_diff->y,
			"month" => $date_diff->m,
			"day" => $date_diff->d,
			"hour" => $date_diff->h,
			"minute" => $date_diff->i,
			"second" => $date_diff->s
		);
	}
	else
	{
		$date_1 = strtotime($date1);
		$date_2 = strtotime($date2);
		$sec = $date_1 - $date_2;
		$sec = intval(abs($sec));

		$ret = array(
			"year" => 0,
			"month" => 0,
			"day" => 0,
			"hour" => 0,
			"minute" => 0,
			"second" => 0
        );
		
		if(0 == $sec)
			return $ret;

		$units = array(
			"year" => 365*24*60*60,
			"month" => 30*24*60*60,
			"day" => 24*60*60,
			"hour" => 60*60,
			"minute" => 60,
			"second" => 1
		);

		foreach($units as $unit => $val)
		{
			$value = floor($sec / $val);
			$ret[$unit] = $value;
			$sec -= $value * $val;
		}

		return $ret;
	}
}

echo cal_diff_date(날짜1, 날짜2);
2016/07/07 10:23 2016/07/07 10:23
Posted
Filed under dog발;/php
As promised here is some Bit.ly PHP example code using their API to generate URLs. There is also some extra code that deals with advanced API usage towards the end of this post. It is important to note that these examples assume that you have cURL installed. I am also opting to use the JSON method of data delivery. Now let's get to the Bit.ly basics and look at a function to generate a shortened URL.
/* Example code */  
$link = "http://www.x-pose.org";   
  
print getSmallLink($link);   
  
function getSmallLink($longurl){   
// Bit.ly   
$url = "http://api.bit.ly/shorten?version=2.0.1&longUrl=$longurl&login=YOURLOGIN&apiKey=YOURAPIKEY&format=json&history=1";   
  
$s = curl_init();   
curl_setopt($s,CURLOPT_URL, $url);   
curl_setopt($s,CURLOPT_HEADER,false);   
curl_setopt($s,CURLOPT_RETURNTRANSFER,1);   
$result = curl_exec($s);   
curl_close( $s );   
  
$obj = json_decode($result, true);   
return $obj["results"]["$longurl"]["shortUrl"];   
}
If you want to get fancy then you can add error checking. Also the variable &history=1 in the URL allows you to keep track of your generated urls via the API. Otherwise they are not saved in your history. Now lets get to some advanced Bit.ly usage. . Let's say you are trying to grab some extra data from the following Bit.ly link: http://bit.ly/info/13SH5 . Of course the most important part of that link is the Hash at the end. Here is an example how to print the Title of the page and the meta description:
/* Example code */  
$hash = '13SH5';   
$url = "http://api.bit.ly/info?version=2.0.1&login=YOURNAME&apiKey=YOURAPIKEY&hash=$hash";   
  
$s = curl_init();   
curl_setopt($s,CURLOPT_URL, $url);   
curl_setopt($s,CURLOPT_HEADER,false);   
curl_setopt($s,CURLOPT_RETURNTRANSFER,1);   
$result = curl_exec($s);   
curl_close( $s );   
  
$obj = json_decode($result, true);   
print $obj["results"]["$hash"]["htmlTitle"];   
print $obj["results"]["$hash"]["htmlMetaDescription"];
Still with me? As you know there is much more data than just the title and description for some of the info pages. Some even include automatically generated categories of what the webpage is about. So lets save those categories into an array that were tagged for this page:
/* Example code */  
foreach($obj["results"]["$hash"]["calais"] as $items){   
            $cat[] = $items[0];   
}  
As you can see Bit.ly is very powerfull stuff. Hopefuly this example code was able to help you out. Stay tuned for my next batch of useful example code that allows you to automatically make blog posts via wordpress.

출처 : http://www.x-pose.org
2011/01/12 09:27 2011/01/12 09:27
Posted
Filed under dog발;/php

ie : urlencode
crossbrowser : base64_encode
2010/08/18 16:38 2010/08/18 16:38