tzfrs/urlextender

This library extends short URLs to longURLs using HTTP-Header Location

0.0.2.1 2015-09-10 14:25 UTC

README

SensioLabsInsight

This library can be used to expand short URLs such as https://t.co/XdXRudPXH5 and get the URL that is behind the short URL using Guzzles head method and reading the Location header

Install

Install via composer:

{
    "require": {
        "tzfrs/urlextender": "0.0.2.1"
    }
}

Run composer install or composer update.

Getting Started

Note: You can also see the examples.php for more examples.

Basic parsing

<?php
require __DIR__ . '/vendor/autoload.php';

$urlExtender = new \tzfrs\URLExtender\URLExtender();

try {
    print $urlExtender->extendURL('https://t.co/XdXRudPXH5'); // https://blog.twitter.com/2013/rich-photo-experience-now-in-embedded-tweets-3
    print $urlExtender->extendURL('https://blog.twitter.com/2013/rich-photo-experience-now-in-embedded-tweets-3'); //https://blog.twitter.com/2013/rich-photo-experience-now-in-embedded-tweets-3
    print $urlExtender->extendURL('http://httpstat.us/404'); // URLExtenderException (404)
    print $urlExtender->extendURL('http://httpstat.us/500'); // URLExtenderException (500)
} catch (\tzfrs\URLExtender\Exceptions\URLExtenderException $e) {
    print $e->getCode() . ': ' . $e->getMessage();
}