<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>phoenixheart - portfolio &#38; more &#187; bit.ly</title>
	<atom:link href="http://www.phoenixheart.net/tag/bitly/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phoenixheart.net</link>
	<description>phoenixheart - portfolio &#38; more</description>
	<lastBuildDate>Wed, 23 Mar 2011 09:47:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<script type="text/javascript">
if (typeof Meebo == "undefined") {
Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};
(function(q){

	var args = arguments;
	if (!document.body) { return setTimeout(function(){ args.callee.apply(this, args) }, 100); }
	var d=document, b=d.body, m=b.insertBefore(d.createElement('div'), b.firstChild); s=d.createElement('script');
	m.id='meebo'; m.style.display='none'; m.innerHTML='<iframe id="meebo-iframe"></iframe>';
	s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;
	b.insertBefore(s, b.firstChild);

})({network:'phoenixheartnet_bo16we'});	}</script>	<item>
		<title>Code snippet #2 &#8211; Shorten Links Using Bit.ly</title>
		<link>http://www.phoenixheart.net/2009/05/code-snippet-2-shorten-links-using-bitly/</link>
		<comments>http://www.phoenixheart.net/2009/05/code-snippet-2-shorten-links-using-bitly/#comments</comments>
		<pubDate>Sat, 09 May 2009 02:29:26 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=285</guid>
		<description><![CDATA[Following the first snippet, here is another small one to shorten a link using Bit.ly. I chose Bit.ly over other link shortening services due to a simple reason: Twitter uses it as default (by now). Code snippet #2 &#8211; Shorten Links Using Bit.ly Purpose Create a shortened URL using Bit.ly. This is extremely useful for [...]]]></description>
			<content:encoded><![CDATA[<p>Following <a href="/2009/05/code-snippet-1-get-latest-tweet/">the first snippet</a>, here is another small one to shorten a link using <a href="http://bit.ly">Bit.ly</a>. I chose Bit.ly over other link shortening services due to a simple reason: Twitter uses it as default (by now).</p>
<h3>Code snippet #2 &#8211; Shorten Links Using Bit.ly</h3>
<h3>Purpose</h3>
<p>Create a shortened URL using Bit.ly. This is extremely useful for your visitors, as they don&#8217;t have to look any further &#8211; just grab it to use right away.</p>
<h3>Requirements</h3>
<ul>
<li>A Bit.ly account (and API key). You can <a href="http://bit.ly/account/register?rd=/">create one for free</a> at their site in seconds. Once logged in, head to Account section and look for a long ugly string starting with &#8220;R_&#8221;.</li>
<li>PHP 5 &gt;= 5.2.0. Your host doesn&#8217;t support PHP 5? Claim your money back and find another host.</li>
</ul>
<h3>The Code</h3>
<p><span id="more-285"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_shortened_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$bitly_api_key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'YOUR KEY HERE'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$bitly_username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'YOUR BIT.LY USERNAME HERE'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://api.bit.ly/shorten?version=2.0.1&amp;longUrl=<span style="color: #006699; font-weight: bold;">$url</span>&amp;login=<span style="color: #006699; font-weight: bold;">$bitly_username</span>&amp;apiKey=<span style="color: #006699; font-weight: bold;">$bitly_api_key</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">utf8_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorCode</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> 
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">results</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$url</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">shortUrl</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// now use it</span>
<span style="color: #b1b100;">echo</span> get_shortened_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.example.com/this-is-a-stupid-long-long-long-url.html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// how about WordPress?</span>
<span style="color: #666666; font-style: italic;">// Just place the function above somewhere in your functions.php theme page and then</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 1. inside The Loop</span>
<span style="color: #b1b100;">echo</span> get_shortened_url<span style="color: #009900;">&#40;</span>get_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 2. outside The Loop</span>
<span style="color: #b1b100;">echo</span> get_shortened_url<span style="color: #009900;">&#40;</span>get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;</pre></td></tr></table></div>

<img style='display:none' id="post-285-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/05/code-snippet-2-shorten-links-using-bitly/',title:'Code snippet #2 &#8211; Shorten Links Using Bit.ly',tweet:'Following the first snippet, here is another small one to shorten a link using Bit.ly. I chose Bit.l',description:'Following the first snippet, here is another small one to shorten a link using Bit.ly. I chose Bit.l'})"><script type='text/javascript'>document.getElementById("post-285-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/05/code-snippet-2-shorten-links-using-bitly/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 2/10 queries in 0.039 seconds using disk
Object Caching 228/237 objects using disk

Served from: www.phoenixheart.net @ 2012-02-04 02:33:32 -->
