Location: PHPKode > scripts > Did You Mean > did-you-mean/Class.Google.DYM.php
<?php
/*
USE EXAMPLE

$DYM = new DYM();
$DYM->lang = 'en-US';

//IF TRUE, DISPLAY AN CORRECT GOOGLE ALTERNATIVE
if($DYM->search('coreqt')){
   echo $DYM->correct;
}
*/

class DYM{

      private $query;

      public $lang = 'pt-BR',
             //SEARCH URL, PLEASE, FOR UPDATES, DON'T REPLACE '#LANGUAGE#' and '#QUERY#'
             $search_addr = 'http://www.google.com.br/search?hl=#LANGUAGE#&q=#QUERY#&meta=',
             //RETURN OF CORRECT ALTERNATIVE
             $correct;
      
      public function __construct(){

      }

      public function search($query){
             $this->query = $query;
             //MAKE ADDRESS
             $resultado = file_get_contents(str_replace(array('#LANGUAGE#','#QUERY#'),array($this->lang,urlencode($this->query)),$this->search_addr));
             //APPLY REG EXP
             preg_match_all("/\<div id\=res class\=med>\<p\>\<font color\=\"#cc0000\" class\=p\>(.*?)\: \<\/font\>\<a href\=\"(.*?)\" class\=p\>(.*?)\<\/a\>/i",$resultado,$matches);
             $this->correct = $matches[3][0];
             //RETURNS
             return isSet($matches[3][0]);
      }

}
?>
Return current item: Did You Mean