Return to Snippet

Revision: 34875
at October 29, 2010 11:11 by adamzwakk


Updated Code
function curlStart($url){
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
	curl_setopt($ch, CURLOPT_POST, FALSE);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_NOBODY, FALSE);
	curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
	curl_setopt($ch, CURLOPT_REFERER, "");
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
	curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; he; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");
	$page = curl_exec($ch);
	return $page;
}

function findWikiInfo($s) {
	$page = curlStart("http://en.wikipedia.org/w/api.php?action=opensearch&search=".urlencode($s)."&format=xml&limit=10");
	$xmlpage = simplexml_load_string($page);
	$wikiarray = array();
	if(count($xmlpage->Section->Item) == 1){
		array_push($wikiarray, array((string)$xmlpage->Section->Item->Text, (string)$xmlpage->Section->Item->Description, (string)$xmlpage->Section->Item->Url));
		return $wikiarray;
	} else {
		for($i = 0;$i != count($xmlpage->Section->Item); $i++){
			array_push($wikiarray, array((string)$xmlpage->Section->Item[$i]->Text, (string)$xmlpage->Section->Item[$i]->Description, (string)$xmlpage->Section->Item[$i]->Url));
		}
		return $wikiarray;
	}
}

print_r(findWikiInfo($_GET['search']));

Revision: 34874
at October 29, 2010 11:09 by adamzwakk


Initial Code
function curlStart($url){
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
	curl_setopt($ch, CURLOPT_POST, FALSE);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_NOBODY, FALSE);
	curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
	curl_setopt($ch, CURLOPT_REFERER, "");
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
	curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; he; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");
	$page = curl_exec($ch);
	return $page;
}

function findWikiInfo($s) {
	$page = curlStart("http://en.wikipedia.org/w/api.php?action=opensearch&search=".urlencode($s)."&format=xml&limit=10");
	$xmlpage = simplexml_load_string($page);
	$wikiarray = array();
	if(count($xmlpage->Section->Item) == 1){
		array_push($wikiarray, array((string)$xmlpage->Section->Item->Text, (string)$xmlpage->Section->Item->Description, (string)$xmlpage->Section->Item->Url));
		return $wikiarray;
	} else {
		for($i = 0;$i != count($xmlpage->Section->Item); $i++){
			array_push($wikiarray, array((string)$xmlpage->Section->Item[$i]->Text, (string)$xmlpage->Section->Item[$i]->Description, (string)$xmlpage->Section->Item[$i]->Url));
		}
		return $wikiarray;
	}
}

findWikiInfo($_GET['search']);

Initial URL


Initial Description
Brings single or multiple results from a mediawiki search back as an easy to use array

Initial Title
Bring MediaWiki info back as array

Initial Tags
php

Initial Language
PHP