| ★ wanayoo — archive 1999 http://www.phpbuilder.com/columns/rasmus19990407.php3 | Nouvelle recherche | Portail wanayoo |
|
|
|||
|
|
|
|
||
|
|
|
Spell Checking and URL TricksRasmus Lerdorf
I needed a simple little example that I could use to show how Apache's ForceType directive can be put to good use with PHP. I chose a URL-based spell checker since one of the newer features of PHP is built-in spell checking and I thought this would interest people as well. This is of course a rather useless example. You can do a lot of quite complex things with the concept presented here. The ForceType directive just changes the MIME type of something to the given type, overriding all other settings for the resource it is applied to. Since it applies to a resource you have to also somehow define which resources it should apply to. I normally use a <Location> block, but <Directory> and <Files> are useful here as well. You should read through How Directory, Location and Files sections work in the Apache documentation to understand the difference between these three better. The big advantage of the <Location> directive is that it can be used in .htaccess files which is good for people who don't have access to change their server's configuration files. To get an idea of what this does try this URL: http://www.lerdorf.on.ca/s/bogus 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>
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>
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
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: http://www.phpbuilder.com/manual/ref.aspell.php3 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. -Rasmus |
||
|
|
|
Sample Code | Columns | Mail Archive | Support | Get Started! | Links | Contribute!
Contact (non support questions) By viewing these pages you agree to the Legal Terms of Service.
Geocrawler.com | GoToCity.com | DirectriCity.com | PHPBuilder.com | The Des Moines City.net |