RSS
 

Google URL Kısaltma Servisi

08 Mar

Merhaba,

Google’un URL kısaltma servisini kullanmak istiyorsanız aşağıdaki şekilde gerçekleştirebilirsiniz.

<?php
namespace webServices{
	class GoogleURL{

		private static $url;

		public function __construct(){}
		public function __destruct(){}

		public function _get(){
			define("serviceURL","http://ggl-shortener.appspot.com/?url=");
			$url      = serviceURL.urlencode(self::$url);
			$request  = file_get_contents($url);
			$response = (array)json_decode($request);
			$result = "<a href='".$response["short_url"]."' target='_blank'>".$response["short_url"]."</a>";
			return $result;

		}

		public function _set($longURL){
			self::$url = $longURL;
		}
	}
}
?>

Kullanımı;

namespace {
	$shortURL = new \webServices\GoogleURL();
	$shortURL->_set("http://www.hakandamar.com");
	print($shortURL->_get());  //http://goo.gl/7aVg
}

Çıktı olarak yeni bir Tab/Pencere ‘de açılan HTML link kontrolü döner. Link’e göre orjinal URL’e ulaşmakta mümkündür.

İyi Çalışmalar.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Diigo
  • email
  • PDF
  • Reddit
  • RSS
  • StumbleUpon
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • DotNetKicks
  • Fleck
  • FriendFeed
  • HackerNews
  • LinkedIn
  • Live
  • Yahoo! Buzz
  • Yigg
 
3 Comments

Posted in PHP

 

Tags: , , , , ,

Leave a Reply

 
 
  1. yasin

    16/03/2010 at 20:05

    public function __construct(){}
    public function __destruct(){}

    acaba bunları neden kullandınız. çok merak ettim.

     
  2. HD

    17/03/2010 at 00:59

    Kullandığım Zend Studio üzerine snippet eklediğimden bir class oluşturduğumda otomatik olarak ekleniyorlar. Siz istemezseniz silebilirsiniz. :)

     
  3. vodo

    25/05/2010 at 18:15

    sade ve güzel olmuş teşekkür ederim.