Login   Register  
PHP Classes
elePHPant
Icontem

File: examples/ShortURL.example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andre Roque Filipe  >  PHP Short URL Class  >  examples/ShortURL.example.php  >  Download  
File: examples/ShortURL.example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Short URL Class
Shorten URLs using different Web services APIs
Author: By
Last change: Added google shortener
Date: 2013-07-03 08:21
Size: 1,285 bytes
 

Contents

Class file image Download
<?php

require_once 'ShortURL.class.php';

//Example of how to use ShortURL class

//You must atleast set the adfly api key and the uid in order to generate adfly urls

$urlShorter ShortURL::getInstance()
    -> 
setParamShortURL::SHORTENER_TYPE_ADFLY'key''adfly_api_key' )
    -> 
setParamShortURL::SHORTENER_TYPE_ADFLY'uid''adfly_user_id' )
    -> 
setParamShortURL::SHORTENER_TYPE_GOOGLE'api''google_api_key' );
    
$url 'http://www.phpclasses.org/browse/author/1183559.html';

$anchorTemplate '<a href="%s" target="_blank">%s</a><br />';

echo 
sprintf$anchorTemplate$url'Original URL' );
echo 
sprintf$anchorTemplate$urlShorter -> getUrl$urlShortURL::SHORTENER_TYPE_ADFLY ), 'adf.ly URL' );
echo 
sprintf$anchorTemplate$urlShorter -> getUrl$urlShortURL::SHORTENER_TYPE_TINYURL ), 'tinyurl.com URL' );
echo 
sprintf$anchorTemplate$urlShorter -> getUrl$urlShortURL::SHORTENER_TYPE_ADFLYShortURL::SHORTENER_TYPE_TINYURL ), 'adf.ly masked as tinyurl.com URL' );
echo 
sprintf$anchorTemplate$urlShorter -> getUrl$urlShortURL::SHORTENER_TYPE_GOOGLE ), 'googleapis.com/urlshortener URL' );
echo 
sprintf$anchorTemplate$urlShorter -> getUrl'http://www.youtube.com/watch?v=dQw4w9WgXcQ'ShortURL::SHORTENER_TYPE_YOUTUBE ), 'y2u.be URL' );