The Incredible App Store Hype
May 24, 2009
The hype surrounding the iPhone App Store continues to persist. It’s been called a gold rush, and stories of one man teams making hundreds of thousands of dollars almost overnight abound. But what does that mean for you, if you want to get into the game? Let’s look at the reality. Read more
The Elusive Female: Developing for Women
May 1, 2009
Females have long been an untapped market when it comes to tech and software. Game publishers know this better than anyone, but nearly every corner of entertainment software would like to attract more female customers. Glowdot Productions “Zen Jar” app for the iPhone seems to have accidentally stumbled onto the secret. I’ll take a look at why the app appeals to women. Read more
Shortening URLs on the fly in PHP
May 1, 2009
For a project I’m currently working on, I wanted to parse input strings looking for URLs and convert them to shortened URLs. The best service to do this in is CR.AM, which is like competing URL shortening services but with some extra features like phishing/spam protection, Twitter integration, and more. If you are doing anything involving Twitter, I highly recommend using cr.am for your URL shortening, as they’ve got some really neat things on the horizon involving Twitter.
More importantly, though, getting it set up was easy. There are two functions: one tokenizes the string to search the string for URLs (in my case, I’m looking for a string that begins with http:// or www. but your needs may vary). Many people would use regular expressions here, I didn’t. My strings are short and easy to parse this way. This post isn’t about how to find URLs in a string, it’s about how to shrink them.
The second function calls up cr.am and requests a hash for the URL. To convert URLs in a string to cr.am URLs, you just pass the string to cramify() and use the output.
-
function cram ($url) {
-
$cramHash = @file_get_contents(‘http://api.cr.am/create/’ . $url);
-
-
list($httpVersion, $statusCode, $message) = explode(‘ ‘,$http_response_header[0], 3);
-
-
if ($statusCode == 200) {
-
return "http://cr.am/".$cramHash;
-
} else {
-
return "";
-
}
-
}
-
-
function cramify ($string) {
-
$tokens = explode(" ",$string);
-
-
foreach ($tokens AS $t) {
-
if (substr($t,0,7) == "http://") {
-
$string = str_replace($t, cram($t), $string);
-
} else if (substr($t,0,4) == "www." && substr($t,4,1) != " ") {
-
$string = str_replace($t, cram("http://".$t), $string);
-
}
-
}
-
-
return $string;
-
}





