PHP Classes

File: examples/gdymBased.php

Recommend this page to a friend!
  Classes of Protung Dragos   PHP Spell Checker   examples/gdymBased.php   Download  
File: examples/gdymBased.php
Role: Example script
Content type: text/plain
Description: Example script for google 'Did you mean' version
Class: PHP Spell Checker
Check spelling of text and get fix suggestions
Author: By
Last change:
Date: 14 years ago
Size: 1,668 bytes
 

Contents

Class file image Download
<?php

// include the class
require_once(dirname(__FILE__)."/../GDYMSpellChecker.class.php");

// instantiate the class
$spellCheck = new GDYMSpellChecker();


/////////////////////////
// set some text to check
$text1 = "Die Commerzbank blickt besorgt in die Zukunft: Das Geldhaus rechnet in der zweiten Jahreshälfte mit einer Zunahme von Kreditausfällen - denn Firmen wie Privatkunden bekommen Probleme, ihre Schulden zu bedienen. Schon jetzt hat das Institut vorsichtshalber knapp eine Milliarde Euro zurückgelegt";
$result = $spellCheck->checkSpelling($text1, "de-DE"); // should return an empty array (text is correct)
//print_r($spellCheck->getWarnings());// get all warnings
//print_r($spellCheck->getErrors());// get all errors
if (count($result) == 0) {
    print
"Text is OK !<br/>";
} else {
    print
"Text has errors !<br/>";
    print
"<pre>";
   
print_r($result);
}
$spellCheck->clearWarnings(); // clear all previous warnings
$spellCheck->clearErrors(); // clear all previous errors

$textWithErrors = "PHP: the quik browm fox jumps over the lazi dog lazi today"; // this text has 3 errors
$result = $spellCheck->checkSpelling($textWithErrors, "en-US"); // will return an array with the wrong words with associated suggestions
//$result = $spellCheck->checkSpelling($textWithErrors, "en-US", false); // will return an array with the wrong words without associated suggestions
//print_r($spellCheck->getWarnings());// get all warnings
//print_r($spellCheck->getErrors());// get all errors
if (count($result) == 0) {
    print
"Text is OK !<br/>";
} else {
    print
"Text has errors !<br/>";
    print
"<pre>";
   
print_r($result);
}

?>