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

About this user

Logan Koester http://logankoester.com

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

Create and lookup tinyurls with PHP

        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];
        } 

Reverse TinyURL

// Resolves a TinyURL.com encoded url to it's source.
// Example: reverse_tinyurl('http://tinyurl.com/2ocfun') => "http://logankoester.com"

function reverse_tinyurl($url){
	$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];
}

Tidy Remote HTML (using a web service)

// Clean up some code using a web service. If you need to do this more quickly I suggest using a local tidy installation
// rather than my web service, but this is nice and easy. :)

function tidied($url) {
  /* Cleans up a page via Tidy, returning the cleaned up html as a string
   * By Logan Koester <logan@logankoester.com> 2007-06-28
   * Props to http://infohound.net/tidy */
  return file_get_contents("http://logankoester.com/tools/tidy.php?q=$url");
}

Regex: "Link to Ebay item"

// Perl-compatible regex to parse hyperlinks to auctions on ebay

/<a href="(http:\/\/cgi.ebay.com\/.*?ViewItem)">/
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS