PHPBuilder - Spell Checking and URL Tricks Page 2

RSS Twitter
Articles Php Functions

Spell Checking and URL Tricks - Page 2

by: Rasmus Lerdorf
July 30, 2000

Now change the "bogus" part of the url to some other word. This is how this was done:
In my Apache server configuration I have this:

<Location /s>
ForceType application/x-httpd-php3
Then I created a file named simply 's' and placed it in my document root. The file contains:

<html><head><title>Simple Spell-Checker</title></head>
<h3>Simple Spell-Checker</h3>
$word substr($PATH_INFO,1); /* strip away first / */
if (aspell_check($aspell_link,$word)) {
"Correct spelling of '$word'<P>\n";
    } else {
"Incorrect spelling of '$word'<P>\n";
"Possible correct spellings include:<br>\n";
$i=0$i count($suggestions); $i++) {
"<li>" $suggestions[$i] . "<br>"
The trick here is that by telling Apache that the /s resource is actually of MIME type application/x-httpd-php3 which is the magical MIME type which triggers PHP, the s file will be run like a PHP script. Any text in the URL following the /s will be put into the $PATH_INFO variable. So in my script I just strip away the first slash and then treat the remaining text as the word I want to spell check.
A couple of other variables get set to useful things on a request like this. Our /s/bogus request from above results in the following:
SCRIPT_FILENAME = /home/httpd/html/s
REQUEST_URI = /s/bogus
PATH_INFO = /bogus
PATH_TRANSLATED = /home/httpd/html/bogus
You can of course discover this yourself by putting a <phpinfo()> tag in your script and loading it up.
Now, for the spell checking part of this. There isn't much to it. You can read about the functions used here:
If you don't have aspell enabled, download the aspell tarball and install it. Note that version 0.27 does not work with PHP since the author did not include a C-callable library. Version 0.26 works fine. The author has promised to bring back the C-callable library in a future version.

« Previous Page

Comment and Contribute

Your comment has been submitted and is pending approval.

Rasmus Lerdorf



(Maximum characters: 1200). You have characters left.