using urlB.org API from PHP

urlborg — Tags: , , — Panayotis @ 16:02

If you are interested to use the urlB.org API from within PHP, here is a simple wrapper.

First download urlborg.php (and, of course, make sure you have your API key).

Now, creating short URLs and getting info about them is easy. Here is an example:

require_once 'urlborg.php' ;
$ub = new urlBorg('use your API key here') ;
$info = $ub->get_info('lgfy') ;
if ($ub->get_error()) {
   echo 'ERROR! Code:' . $ub->get_error('n') .
   ' desc:' . $ub->get_error('s') ;
} else {
   print_r($info) ;
}
$short = $ub->create_new('http://vrypan.net/') ;
if ($ub->get_error()) {
    echo 'ERROR! Code:' . $ub->get_error('n') .
    ' desc:' . $ub->get_error('s') ;
} else {
    print_r($short) ;
}

(the example is included in the class headers. Don’t copy-paste it from this post since Wordpress seems to change the quotes in ways that PHP doesn’t like :-)

3 Comments »

  1. Thank you, vrypan!
    Very useful

    Comment by nmpardakis — 2008-02-13 @ 20:02
  2. You have an error in the 3rd line:
    $info = $u->get_info(’lgfy’) ;
    must be:
    $info = $ub->get_info(’lgfy’) ;
    also check this out:
    http://linkbunch.com/
    feel free to delete this comment.

    Comment by leo — 2008-02-14 @ 04:02
  3. @leo: fixed. Thanks!

    Comment by Panayotis — 2008-02-14 @ 09:02

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2008 vrypan|net|log | powered by WordPress with Barecity