phpurltinyurl

Api for url Expander in php


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.


Solution

  • 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.