:)

Sunday, August 10, 2008

Auto Wikipedia Article Locator

Well, tonight after failing to get required results from my algorithms and after getting really bored with extreme Python, I decided to write a cool sniped:
Often blogs have links to Wikipeida articles, e.g. if I am writing something about Lahore University of Management Sciences, I write as Lahore University of Management Sciences :P, To make it generic so that people don't waste time searching Wikpedia for the link to article, I wrote a small PHP snippet which automatically forwards to the first article which wikipidia has about this topic.
BUT There is only one limitation, it forwards to the first result in Wikipedia which might not be the required one, but if you want some obvious article ( I mean if you are writing for Pakistan then the link to Pakistan's article is quite known and is obvious), it will guide you to the correct article.

Usage: use this as hyperlink as LUMS

Wikipedia.php

$tosearch = trim($_GET['go']);
$tosearch=str_replace(" ","+",$tosearch);
//using wikipedia API here
$result = file_get_contents("http://en.wikipedia.org/w/api.php?action=opensearch&search=".$tosearch."&limit=1");
$result= split('"',$result);
$result= $result[3];
$forwardto="http://en.wikipedia.org/wiki/".str_replace(" ","_",$result);
header('Location: '.$forwardto);
?>

1 comments:

ali said...

Oh my gaush what a helpfull snippet i loved it

Blog Archive

My Associations

Volunteer Internet Environment Watch (VIEW)
(which is no more volunteer based)

Sahana - Disaster Management System
Sahana is my Google Summer of Code Project (2009)