#The most simple PHP url shortner!
This code uses tinyurl.com to short urls, so thanks to the cretor of the awesome site.
Looking for a JS version? Go here: https://gist.github.com/StephanStanisic/b7017b1a8cd3c785e332. I also have a PHP version there (one line!).
##Usage:
tinyurl("http://google.com")
returns http://tinyurl.com/2tx
tinyurl("http://github.com")
returns http://tinyurl.com/2lekkm
##Sample application
<?php
function tinyurl($url) {
$data = file_get_contents('http://tinyurl.com/create.php?url='.urlencode($url));
preg_match_all ("/<b>([^`]*?)<\/b>/", $data, $matches);
return $matches[1][1];
}
if( isset( $_GET["url"] ) ) {
echo "Your short url: ".tinyurl($_GET["url"]);
}
?>
<form style="text-align: center;">
<h1>Url shortner</h1>
<input type="text" name="url" placeholer="Url to short here" /><br />
<input type="submit" value="Short!" />
</form>