Skip to content

Instantly share code, notes, and snippets.

@antimatter15
Created September 23, 2009 22:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save antimatter15/192346 to your computer and use it in GitHub Desktop.
Save antimatter15/192346 to your computer and use it in GitHub Desktop.
function search_wolframalpha($query){
$url2 = 'http://www.wolframalpha.com/input/?i='.urlencode($query);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
//curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
//curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url2);
$r = curl_exec($ch);
$doc = new DOMDocument();
@$doc->loadHTML($r);
$results = $doc->getElementById("results");
foreach($results->getElementsByTagName("img") as $img){
$src = $img->getAttribute("src");
if($src != "/images/loadingdots.gif"){
echo "<img src='".$src."'><br>";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment