May 12, 2014 10:49 am

How to Expand Short URLs To Original URL Using PHP and cURL

Hello guyz today I am going to write a tutorial on short URLs, there are many URL shortening services available and you don’t know where your browser is taking you by clicking that URL and many people don’t want to open them even I am also one of them, so here I am giving you a solution where you can get original URL behind the short link without opening that page and doing this with PHP cURL and preg_replace methods.

How to Expand Short URLs To Original URL Using PHP and cURL

Also Read: HTTP POST Using PHP cURL

A very easy and simple snippet that can perform this task.

PHP Snippet:

How it works

Above cURL extract only header information in which we get website original location and we parsed that info and show you in output. curl_setopt($ch,CURLOPT_HEADER,true); this filed asks server to give me only your header information not the body of the in website.

Call this function:

This will display you the original URL with short URL.

I hope this tutorial helps you please don’t forget to give us your feedback in comments.

Book: PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.


Tutorial Categories:
  • MatJengkol

    cool, syukran

  • MatJengkol

    cool, syukran

  • Mohd Farhan Rizwan

    SIr Curl is not working with https(ssl).