• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

Services/H03-May-2022-1,532669

tests/H03-May-2022-238106

README.textileH A D05-Apr-20111.6 KiB7753

README.textile

1h2. Services_ShortURL
2
3h3. Introduction
4
5Services_ShortURL is an abstract interface to the plethora of short/tiny/miny
6URL services written in PHP5 for PEAR. It allows you to easily create or expand
7short URL's. In addition to expanding and shortening short URL's it has helper
8functions for detecting what type of short URL service a URL belongs to and
9extracting short URL's and expanding them from blogs of text.
10
11h3. Services
12
13* bit.ly
14* Digg
15* is.gd
16* short.ie
17* TinyURL
18* tr.im
19
20h3. Shortening a URL
21
22<pre>
23<code>
24<?php
25
26$url = 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html';
27require_once 'Services/ShortURL.php';
28
29$api   = Services_ShortURL::factory('TinyURL');
30$short = $api->shorten($url);
31
32// I'm short!
33var_dump($short);
34
35?>
36</code>
37</pre>
38
39h3. Expanding a URL
40
41<pre>
42<code>
43<?php
44
45$url = 'http://tinyurl.com/jumvn';
46require_once 'Services/ShortURL.php';
47
48$api  = Services_ShortURL::factory('TinyURL');
49$long = $api->expand($url);
50
51// Should be http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
52var_dump($short);
53
54?>
55</code>
56</pre>
57
58h3. Extracting known URLs
59
60If you have a blob of text that may or may not contain short URLs in it, you can easily extract them with the <code>Services_ShortURL::extract()</code> method. This method looks through the text for known short URLs, extracts them, expands them and then returns an array with a key/value pair of short/long URLs.
61
62<pre>
63<code>
64<?php
65
66$txt = 'Hey check out http://tinyurl.com/jumvn and http://bit.ly/EojDf if you like politics.';
67require_once 'Services/ShortURL.php';
68
69$urls = Services_ShortURL::extract($txt);
70
71// Will be a hash with short => long URls in it.
72print_r($urls);
73
74?>
75</code>
76</pre>
77