Hi!

After years I decided to sign up!

Can you please tell me of a bot tutorial or getting a solution to my problem. What direction should I be going.

I want to make a PHP script that searches a MySQL table's columns, rows and then returns all the spelling mistakes in those cells..

Anyone?

Thanks

Dani AI

Generated

you can do this, but not inside MySQL. Let MySQL store pages; do the spell-check in PHP, comparing tokens against a dictionary as and hinted. The reliable route is PHP’s pspell (Enchant) extension backed by Aspell/Hunspell dictionaries. That way you can flag unknown words and offer suggestions, without trying to bend SQL into a spell checker. (php.net)

To scan HTML safely, parse it and extract only text nodes (skip script/style), then check each unique word. Small example:

$html = file_get_contents($path);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$text = html_entity_decode($dom->textContent, ENT_QUOTES, 'UTF-8');

$cfg = pspell_config_create('en');
pspell_config_mode($cfg, PSPELL_FAST);
$ps = pspell_new_config($cfg);

$words = preg_split("/[^a-z']+/i", strtolower($text), -1, PREG_SPLIT_NO_EMPTY);
$miss = [];
foreach (array_unique($words) as $w) {
    if (!ctype_digit($w) && !pspell_check($ps, $w)) {
        $miss[$w] = array_slice(pspell_suggest($ps, $w), 0, 3);
    }
}
print_r($miss);

DOMDocument gives you robust HTML parsing; pspell_check/suggest handle the dictionary logic. Install the language dictionaries you need (e.g., en_US) so pspell has data to work with. (php.net)

If you still want SQL to help with suggestions, you can keep your wordlist in a table and use phonetic matching to broaden results, then rank in PHP:

SELECT word
FROM dictionary
WHERE SOUNDEX(word) = SOUNDEX(?)
LIMIT 20;

Note: SOUNDEX/SOUNDS LIKE are English-oriented and can be inconsistent with UTF-8; use them only as a coarse prefilter. Final scoring (e.g., Levenshtein) should happen in PHP as @diafol suggested. (dev.mysql.com)

For thousands of pages, run this as a CLI job in batches, cache dictionary lookups, and store findings as url, word, context, suggestions to review later.

Recommended Answers

All 8 Replies

you can search for any ready made spell checked available else where.
You won't be able to do it alone with php unless you have a huge database of the words, against which you can check your spellings.

Yea, whatever you do, you will need a list of correctly spelled words to test against. PHP has no way to determine what is and is not incorrectly spelled unless it has something to compare it to.

Once you have that list, however, PHP has a few functions you can use to "guess" the correct word. Like the levenshtein function. (See the example there)

I have massive database of spelling words, dictionaries and grammar queries..

Is there no match like and replace type thing I can do?

If search.php action is..

$get request [q]

sql = select * all from products where q="request query form q" and match with spellinglist where word is like "request query form q" and like "spellinglist" suggestion

yes, you got it right. But if the spelling is wrong , say the user is searching for "camel"
and he types "camal: then your code need to do this too.
query should include...."..like '%cam[single char]l' " etc
or "..like '%cam%' " etc.
In short you will need to experiment with the wild cards little bit

Is there any way to do via an array.

I actually want to scan a html document source code and try to find spelling mistakes in it..

see if this is useful for you,
and

Thanks. I tried spellr.us.. that seems to be the best - I want to scan thousands of pages though.. and I want to do it myself free..

Member Avatar for Member #120589

Like some mentioned, you'll need to decide on your options.
Also you'll need to ensure that punctuation marks are not included
in your words to check. It's possible that some words will have numbers in them (e.g. chemicals), so you may want to include words that have numbers in them, but not numbers by themselves.

If you get a 'nomatch', you'll then need to trawl for a series of wildcarded options and list them alphabetically.

You could use an autosuggest (ajax) list, although a MASSIVE db may slow down this function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.