Adam wanted a spellchecker for his new blog without paying for it. I outlined a possible solution:
if you want to do it with writing as little code as possible then you will want to do it in Bash where you have "spell" and "cat" already. www.cygwin.com however, if you want to do it in the easiest way for you possible perhaps an ASP page on your local machine that you fill in the details on which spell checks against the attached dictionary file offering both a preview with highlighted possible spelling mistakes The spell check is just: ' remove all punctuation symbols with Replace ' replace all whitespace chars with spaces ' recursively replace 2 spaces with one space (this step may be unnecessary) ' split on space and compare each var in resulting array with file (contents ' of which are in memory - its just an InStr(vbCrLf & strWord & CrLf, strDict) ' warning: dict file may be newlines only not CRLF Or better yet get the words with a regex (supported in IIS5) along the lines of [^.;& ]* and then cycle through the matches. So program flow is like this: Big text box with Preview and BlogIt buttons Preview => Show text from box with possible spelling mistakes in red and box appears below for editing with Preview and BlogIt buttons BlogIt => Force it through to submit page of blogspot. Cool!
And while he messed with how to get the spellchecked story to post from his local machine to his blog I wrote it (in ASP).
Then it turns out that the blogger API is for XML-RPC which ASP can’t do (easily). So he wants me to rewrite, preferably in PHP which is what he has the submission stuff in.
I had never written any PHP before but I did the conversion which apart from a few sticking points was very easy (JSP/ASP/PHP are very very similar in the fundamentals).
The code shortened to 298 lines (from 363) and no longer requires an external sorting library as there is one built in to PHP.
Part of this reduction in size was due to the inlining of the ExtractWords function as with PHP’s regular expression support (just like Perl’s) it was a two-liner.
BUT there is no equivalent of Option Explicit
in PHP! The best you can do is set ERROR_ALL in php.ini which is not the same thing at all. I must be overlooking something but I can’t find information about it anywhere on the web.
I still have some kind of problem with escaped apostrophes (PHP’sbastard hack called magic_quotes which I was happier not to know about) and the sorting is irrelevant because the algorithm does not take advantage of it and stop searching the dictionary when there is no longer any chance the word is in there (for that matter the dictionary isn’t sorted either!)
Check out the new PHP5 error level E_STRICT:
2048 E_STRICT (integer) Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. since PHP 5