I've dictionary array with correct words:
<?php
$dict = array("apple","windows","microsoft","happy");
?>
I tried some options for correction, but it did not help me to solve my problem. I will give an example of one of the methods used
<?php
$config_dic= pspell_config_create ('en');
function orthograph($string)
{
// Suggests possible words in case of misspelling
$config_dic = pspell_config_create('en');
// Ignore words under 3 characters
pspell_config_ignore($config_dic, 3);
// Configure the dictionary
pspell_config_mode($config_dic, PSPELL_FAST);
$dictionary = pspell_new_config($config_dic);
// To find out if a replacement has been suggested
$replacement_suggest = false;
$string = explode('', trim(str_replace(',', ' ', $string)));
foreach ($string as $key => $value) {
if(!pspell_check($dictionary, $value)) {
$suggestion = pspell_suggest($dictionary, $value);
// Suggestions are case sensitive. Grab the first one.
if(strtolower($suggestion [0]) != strtolower($value)) {
$string [$key] = $suggestion [0];
$replacement_suggest = true;
}
}
}
if ($replacement_suggest) {
// We have a suggestion, so we return to the data.
return implode('', $string);
} else {
return null;
}
}
$search = $_POST['input'];
$suggestion_spell = orthograph($search);
if ($suggestion_spell) {
echo "Try with this spelling : $suggestion_spell";
}
$dict = pspell_new ("en");
if (!pspell_check ($dict, "lappin")) {
$suggestions = pspell_suggest ($dict, "lappin");
foreach ($suggestions as $suggestion) {
echo "Did you mean: $suggestion?<br />";
}
}
// Suggests possible words in case of misspelling
$config_dic = pspell_config_create('en');
// Ignore words under 3 characters
pspell_config_ignore($config_dic, 3);
// Configure the dictionary
pspell_config_mode($config_dic, PSPELL_FAST);
$dictionary = pspell_new_config($config_dic);
..................................................
The idea is there but could not realize. If you can understand and help as something with something then for you earlier, thank you. The idea is that it checks each word for similarity from an array with the correct words in percentages well or in anything and if the words 90-95% coincide with the word in the mass then replace it with the correct version. For example, in the word maximum, 2-3 letters can be omitted. Most people will miss 1-2 letters. Such functionality is in google translate. I want to implement such a functional in my project.
The user, for example, can enter a word in such different incorrect variants:
$textarea = "Windows - Widows, Apple - Aple";
There are such cases that the user adds what is not needed letters in the word
$text = "microsoft - microosoft, happy - haapy";
I would like to create my own function to solve this problem. Than to use the side extended ... Therefore for an example can show what that variants.