Search code examples
phpcurlshort-url

file_get_contents() for short urls


file_get_contents() doesn't read data for short urls Example:

  • http://wp.me/pbZy8-1WM,
  • http://bit.ly/d00E2C

Please help me in handle this. OR Is there any CURL function to handle above links?


Solution

  • This in general works fine. If you find it doesn't do the right thing you can explicitly use a stream context:

    $url = "http://bit.ly/d00E2C";
    $context = stream_context_create(array('http' => array('max_redirects' => 5)));
    $val = file_get_contents($url, false, $context);
    

    should do it. No need to touch CURL for that.