note 70798 added to ref.pspell
| From: | shollandatnapervillegidotcom at osu1 dot php dot net | Date: | Sat, 28 Oct 2006 18:48:11 +0000 |
| Subject: | note 70798 added to ref.pspell | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119212@lists.php.net to get a copy of this message | ||
Back in 10/2002 csnyder at chxo dot com wrote the first comment about the spell functions, and wrote
a very sophisticated spell check with a direct call to aspell. In a similar vein, I wrote a
simplified a PHP function that will spell check a string and insert tags before and after the
misspelled words. Auto-correction is not offered.
<?
function spellcheck($string) {
// Entry: $string: Text to spellcheck.
// Returns: string with '<strong>' and '</strong>' inserted before
and
// after misspellings.
$pre='<strong>'; // Inserted before each mis-spelling.
$post='</strong>'; // Inserted after each mis-spelling.
$string=strtr($string,"\n"," ");
// Drop newlines in string. (It bothers aspell in this context.)
$mistakes =
echo $string | /usr/local/bin/aspell list;
// Get list or errors.
$offset=0;
foreach (explode("\n",$mistakes) as $word)
// Walk list, inserting $pre and $post strings. I move along and
// do the insertions, keeping track of the location. A global replace
// with str_replace($string,$pre.$work.$post) is problematic if the
// same misspelling is found more than once.
if ($word<>"") {
$offset=strpos($string,$word,$offset);
$string=substr_replace($string, $post, $offset+strlen($word), 0);
$string=substr_replace($string, $pre, $offset, 0);
$offset=$offset+strlen($word)+strlen("$pre $post");
};
return $string;};
?>
For this to work on your system, see if /usr/local/bin/aspell list runs from the shell. It needs to
get input from standard input. You may not be able to run apell without the path for PHP because
the PATH variable may be different in the PHP invocation from a shell invocation.
----
Server IP: 66.163.161.117
Probable Submitter: 67.184.33.112
----
Manual Page -- http://www.php.net/manual/en/ref.pspell.php
Edit -- https://master.php.net/note/edit/70798
Del: integrated -- https://master.php.net/note/delete/70798/integrated
Del: useless -- https://master.php.net/note/delete/70798/useless
Del: bad code -- https://master.php.net/note/delete/70798/bad+code
Del: spam -- https://master.php.net/note/delete/70798/spam
Del: non-english -- https://master.php.net/note/delete/70798/non-english
Del: in docs -- https://master.php.net/note/delete/70798/in+docs
Del: other reasons-- https://master.php.net/note/delete/70798
Reject -- https://master.php.net/note/reject/70798
Search -- https://master.php.net/manage/user-notes.php