PHP: How to expand/contract Tinyurls -
in php, how can replicate expand/contract feature tinyurls on search.twitter.com?
if want find out tinyurl going, use fsockopen connection tinyurl.com on port 80, , send http request this
get /dmsfm http/1.0 host: tinyurl.com
the response like
http/1.0 301 moved permanently connection: close x-powered-by: php/5.2.6 location: http://en.wikipedia.org/wiki/tinyurl content-type: text/html content-length: 0 date: mon, 15 sep 2008 12:29:04 gmt server: tinyurl/1.6
example code...
<?php $tinyurl="dmsfm"; $fp = fsockopen("tinyurl.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "get /$tinyurl http/1.0\r\n"; $out .= "host: tinyurl.com\r\n"; $out .= "connection: close\r\n\r\n"; $response=""; fwrite($fp, $out); while (!feof($fp)) { $response.=fgets($fp, 128); } fclose($fp); //now parse location: header out of response } ?>
Comments
Post a Comment