Skip to content

Instantly share code, notes, and snippets.

@melihbuyuk
Created June 13, 2011 09:42
Show Gist options
  • Save melihbuyuk/1022536 to your computer and use it in GitHub Desktop.
Save melihbuyuk/1022536 to your computer and use it in GitHub Desktop.
Google Did You Mean PHP Class
class DYM{
private $sorgu;
public $dil = 'tr',
//Arama url'si
$aranan_kelime = 'http://www.google.com.tr/search?hl=#dil#&q=#sorgu#&meta=',
//Donen Sonuc Dogru veya Yanlis.
$dogru;
public function __construct(){ }
public function ara($sorgu){
$this->sorgu = $sorgu;
//Adres Ayrastirimi.
$sonuc = file_get_contents(str_replace(array('#dil#','#sorgu#'),array($this->dil,urlencode($this->sorgu)),$this->aranan_kelime));
// Dom Yukleyelim.
$doc = new DOMDocument();
@$doc->loadHTML($sonuc);
$aTag = $doc->getElementByID('topstuff')->getElementsByTagName('a');
foreach($aTag as $nesne){
if($nesne->getAttribute('class') == 'spell'){
$this->dogru = $nesne->nodeValue;
return true;
}
}
//Donus
return false;
}
}
//Kullanimi
$DYM = new DYM();
$DYM->dil = 'tr';
//Eger Donen Sonuc Istenilen Kelime Degil ISe googlenin Alternatif Onerdigi Isimleri Goster.
if($DYM->ara('islm')){
echo $DYM->dogru;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment