Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Create and lookup tinyurls with PHP (See related posts)

        function reverse_tinyurl($url){
            // Resolves a TinyURL.com encoded url to it's source.
            $url = explode('.com/', $url);
            $url = 'http://preview.tinyurl.com/'.$url[1];
            $preview = file_get_contents($url);
            preg_match('/redirecturl" href="(.*)">/', $preview, $matches);
            return $matches[1];
        }
        
        function tinyurl($url){
        // Shortens a url
            $html = file_get_contents("http://tinyurl.com/create.php?url=".$url);
            preg_match('/http:\/\/preview\.tinyurl\.com\/(.*)<\/b>/', $html, $matches);
            return "http://tinyurl.com/".$matches[1];
        } 

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts