Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9224199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:15:33+00:00 2026-06-18T04:15:33+00:00

I couldn’t convert a double shortened URL to expanded URL successfully using the below

  • 0

I couldn’t convert a double shortened URL to expanded URL successfully using the below function I got from here:

function doShortURLDecode($url) {
        $ch = @curl_init($url);
        @curl_setopt($ch, CURLOPT_HEADER, TRUE);
        @curl_setopt($ch, CURLOPT_NOBODY, TRUE);
        @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $response = @curl_exec($ch);
        preg_match('/Location: (.*)\n/', $response, $a);
        if (!isset($a[1])) return $url;
        return $a[1];
    }

I got into trouble when the expanded URL I got was again a shortened URL, which has its expanded URL.

How do I get final expanded URL after it has run through both URL shortening services?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:15:34+00:00Added an answer on June 18, 2026 at 4:15 am

    Finally found a way to get the final url of a double shortened url. The best way is to use longurl api for it.

    I am not sure if it is the correct way, but i am at last getting the output as the final url needed 🙂

    Here’s what i did:

    <?php
     function TextAfterTag($input, $tag)
     {
            $result = '';
            $tagPos = strpos($input, $tag);
    
            if (!($tagPos === false))
            {
                    $length = strlen($input);
                    $substrLength = $length - $tagPos + 1;
                    $result = substr($input, $tagPos + 1, $substrLength); 
            }
    
            return trim($result);
     }
    
     function expandUrlLongApi($url)
     {
            $format = 'json';
            $api_query = "http://api.longurl.org/v2/expand?" .
                        "url={$url}&response-code=1&format={$format}";
            $ch = curl_init();
            curl_setopt ($ch, CURLOPT_URL, $api_query );
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
            curl_setopt($ch, CURLOPT_HEADER, false);
            $fileContents = curl_exec($ch);
            curl_close($ch);
            $s1=str_replace("{"," ","$fileContents");
            $s2=str_replace("}"," ","$s1");
            $s2=trim($s2);
            $s3=array();
            $s3=explode(",",$s2);
            $s4=TextAfterTag($s3[0],(':'));
            $s4=stripslashes($s4);
            return $s4;
     }
     echo expandUrlLongApi('http://t.co/dd4b3kOz');
    ?>
    

    The output i get is:

    "http://changeordie.therepublik.net/?p=371#proliferation"
    

    The above code works.

    The code that @cryptic shared is also correct ,but i could not get the result on my server (maybe because of some configuration issue).

    If anyone thinks that it could be done by some other way, please feel free to share it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I couldn't find anything about getting the total JSON record count using jQuery. Here
Couldn't figure out how to word the question accurately, so here's an example: Given
I couldn't find the actual function's code as I am interested in how it
couldn't access registry HKLM keys from windows xp limited/guest user accounts public int GetEnabledStatus()
Couldn't the diamond problem be resolved just by using the first inherited declaration found?
Couldn't find a function for this. I'm assuming I need to use regex? I'm
Couldn't come up with a good title for this. I've got a build in
couldn't find similar posts, so posting my own question. I got variable array of
Couldn't manage chaining calls using coffee script. I'm trying to reproduce this in coffee
Couldn't find a better way to phrase this question. Here's the deal: I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.