Created
June 13, 2011 09:42
-
-
Save melihbuyuk/1022536 to your computer and use it in GitHub Desktop.
Google Did You Mean PHP Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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