By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,723 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,723 IT Pros & Developers. It's quick & easy.

Simple PHP script?

P: n/a
Here is what I want to do. I want to be able to load a list of
correctly spelled words in and then the script will come up with
misspelled versions of that word and insert it into a mysql db. My
question is, where would I start?

Thanks,
Bryan
Oct 3 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 3 Oct, 01:47, BryanA <Bryan.Andr...@gmail.comwrote:
Here is what I want to do. I want to be able to load a list of
correctly spelled words in and then the script will come up with
misspelled versions of that word and insert it into a mysql db. My
question is, where would I start?

Thanks,
Bryan
Are you having problems with the basic loading and saving, or with the
"generating mispelled" bit (which looks vaguely-defined to me) ?
Oct 3 '08 #2

P: n/a
Message-ID:
<20**********************************@u65g2000hsc. googlegroups.comfrom
BryanA contained the following:
>Here is what I want to do. I want to be able to load a list of
correctly spelled words in and then the script will come up with
misspelled versions of that word and insert it into a mysql db. My
question is, where would I start?
What for?
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk - http://4theweb.co.uk
Oct 3 '08 #3

P: n/a
On 3 Oct, 01:47, BryanA <Bryan.Andr...@gmail.comwrote:
Here is what I want to do. I want to be able to load a list of
correctly spelled words in and then the script will come up with
misspelled versions of that word and insert it into a mysql db. My
question is, where would I start?

Thanks,
Bryan
Work out an algorithm, implement the algorithm in PHP then test it.

C.
Oct 3 '08 #4

P: n/a
BryanA wrote:
Here is what I want to do. I want to be able to load a list of
correctly spelled words in and then the script will come up with
misspelled versions of that word and insert it into a mysql db. My
question is, where would I start?

Thanks,
Bryan
An algorithm such as the one used in:

http://www.norvig.com/spell-correct.html

can be re-written in php as in the following:

$word = "Spelling";

$word = strtolower($word);

$length = strlen($word);

// deletion
for ($i=0;$i<$length;$i++)
$variants[] = substr($word,0,$i) .
substr($word,$i+1,$length-$i-1);

// transposition
for ($i=0;$i<$length-1;$i++)
$variants[] = substr($word,0,$i) .
substr($word,$i+1,1) .
substr($word,$i,1) .
substr($word,$i+2,$length-$i-2);

// alteration
for ($i=0;$i<$length;$i++)
for ($c=ord('a'); $c <= ord('z'); $c++)
$variants[] = substr($word,0,$i) .
chr($c) .
substr($word,$i+1,$length-$i-1);
// insertion
for ($i=0;$i<$length+1;$i++)
for ($c=ord('a'); $c <= ord('z'); $c++)
$variants[] = substr($word,0,$i) .
chr($c) .
substr($word,$i,$length-$i);
// remove identical variants
foreach ($variants as $n =$variant)
if ($variant == $word)
unset($variants[$n]);

print_r($variants);

-Lee
Oct 3 '08 #5

P: n/a
Response to BryanA <Br***********@gmail.com>:
Here is what I want to do. I want to be able to load a list of
correctly spelled words in and then the script will come up with
misspelled versions of that word and insert it into a mysql db. My
question is, where would I start?
Unit tests are an ideal place to start. Look for the functionality
you desire.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Oct 9 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.