Code Monkey home page Code Monkey logo

services_shorturl's Introduction

Services_ShortURL

Introduction

Services_ShortURL is an abstract interface to the plethora of short/tiny/miny
URL services written in PHP5 for PEAR. It allows you to easily create or expand
short URL’s. In addition to expanding and shortening short URL’s it has helper
functions for detecting what type of short URL service a URL belongs to and
extracting short URL’s and expanding them from blogs of text.

Services

  • bit.ly
  • Digg
  • is.gd
  • short.ie
  • TinyURL
  • tr.im
  • piep.net

Shortening a URL


<?php

$url = 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html';
require_once 'Services/ShortURL.php';

$api   = Services_ShortURL::factory('TinyURL');
$short = $api->shorten($url);

// I'm short!
var_dump($short);

?>

Expanding a URL


<?php

$url = 'http://tinyurl.com/jumvn';
require_once 'Services/ShortURL.php';

$api  = Services_ShortURL::factory('TinyURL');
$long = $api->expand($url);

// Should be http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
var_dump($short);

?>

Extracting known URLs

If you have a blob of text that may or may not contain short URLs in it, you can easily extract them with the Services_ShortURL::extract() 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.


<?php

$txt = 'Hey check out http://tinyurl.com/jumvn and http://bit.ly/EojDf if you like politics.';
require_once 'Services/ShortURL.php';

$urls = Services_ShortURL::extract($txt);

// Will be a hash with short => long URls in it.
print_r($urls);

?>

services_shorturl's People

Contributors

blam avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.