Ho scaricato uno script per la correzione ortografica. Volevo sapere il tipo di istruzione da utilizzare per correggere un testo memorizzato nella variabile $testo.
Allego lo script:
<?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));
// initialize DOM
$doc = new DOMDocument();
@$doc->loadHTML($resultado);
$aTag = $doc->getElementByID('topstuff')->getElementsByTagName('a');
foreach($aTag as $object){
if($object->getAttribute('class') == 'spell'){
$this->correct = $object->nodeValue;
return true;
}
}
//RETURNS
return false;
}
}
?>