Api for url Expander in php

839 Views Asked by At

I create a short url using tinyurl Api. now i am finding Api that expand these tinyurls i tried to find but only get websites that expand the url not api. I want api that dynamically expand the url in my website.

2

There are 2 best solutions below

2
vikash On BEST ANSWER

On your Question I think You want to expand tiny Urls. Its is also Possible using Curl And Php .

<?php
function ger_origenal_url($url)
{
    $ch = curl_init($url);
    curl_setopt($ch,CURLOPT_HEADER,true); // Get header information
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,false);
    $header = curl_exec($ch);

    $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header)); // Parse information

    for($i=0;$i<count($fields);$i++)
    {
        if(strpos($fields[$i],'Location') !== false)
        {
            $url = str_replace("Location: ","",$fields[$i]);
        }
    }
    return $url;
}

$url            = 'your tiny url';  
$original_url   = ger_origenal_url($url); // Calling function with short url
echo $original_url;
exit;

?>

I think this is helpful for you.

0
Mukesh Swami On

What exactly you want to achieve , As i understand you want to add something to your tinyurl with some api help,You can append these url simply by your code , or else if you want to add some data in these urls , You can take a look at branch.io it is good for adding many data in a short url .Like deeplink