ss_blog_claim=88d0a386a6277415f42c9ee5561ded98

Archive for October 12th, 2007

Uncloaking TinyURL

Welcome to another PHP tutorial from ForgedEuphoria. This time around we’ll be looking at how to use PHP to input a TinyURL and display the real page’s URL, thus ‘uncloaking’ the link. Let’s get into it!

Here’s the full code for our function:

<?php
function reverseTinyURL($url){
    $url = explode('.com/', $url);
    $url = 'http://preview.tinyurl.com/'.$url[1];
    $preview = file_get_contents($url);
    preg_match('/redirecturl" href="(.*)">/', $preview, $matches);
    return $matches[1];
}
?>

Download this code: revTinyURL.phps

Let’s break it down..

The first line of code declares that it is a function, ‘reverseTinyURL’.

function reverseTinyURL($url){

Next our function splits the URL, starting with .com. Next it gets the source of TinyURL preview page, which is where we will find our uncloaked URL.


$url = explode('.com/', $url);
$url = 'http://preview.tinyurl.com/'.$url[1];
$preview = file_get_contents($url);

Finally it uses the PHP preg_match function to find the line of HTML where our link is hidden and then returns it as a URL.


preg_match('/redirecturl" href="(.*)">/', $preview, $matches);
return $matches[1];
}

If you want to know how to use the function, see below.

<? reverseTinyURL('http://tinyurl.com/2frj9u'); // returns http://www.forgedeuphoria.com/blog/ ?>

Download this code: revTinyURL-example.phps

Pretty neat, eh?

Questions, comments, something unclear? Leave a comment.

If you liked this post, buy me a coffee!

GoLive Mobile Marketing

GoLive Mobile is a leading provider of mobile marketing software. In this technological day and age where your office can go home with you in your pocket or tucked under your arm, your business needs to be available 24/7. Whether it be online or over the phone, more and more people are turning to their handheld mobile devices to access their information. That’s why you need GoLive Mobile. They specialise in SMS Marketing, Mobile Website Design and Hosting and a plethora of other specialty areas. A recent article on MarketingVox shows just how much mobile devices are impacting on business life. According to the article, 28 percent of global brands surveyed have already launched live SMS (text) campaigns and 18 percent have launched live MMS (multimedia) campaigns. The survey also found that more brands expect to spend a greater proportion of their marketing budget on mobile campaigns in the near future: 71 percent project that they’ll spend up to 10 percent of their budget on mobile marketing within two years. The survey also presents a bunch of more interesting key finds, so it’s well worth a read.

Do you want to get ahead in today’s business market? Go with GoLive Mobile!

If you liked this post, buy me a coffee!




October 2007
M T W T F S S
« Sep   Nov »
1234567
891011121314
15161718192021
22232425262728
293031  

RSS  


Posts (RSS) Posts     Comments (RSS) Comments
 Add to Technorati Favorites


advertisements  






top commentators