function text_handler($data)
{
    //quick and dirty hack
    $data = str_replace('$', ' $ ', $data);
    $data = str_replace('?', ' ? ', $data);
    $data = str_replace('!', ' ! ', $data);
    $data = str_replace('.', ' . ', $data);
    $data = str_replace(',', ' , ', $data);
    $data = str_replace(';', ' ; ', $data);
    $data = str_replace(':', ' : ', $data);
    $data = str_replace('(', ' ( ', $data);
    $data = str_replace(')', ' ) ', $data);
    $data = str_replace('{', ' { ', $data);
    $data = str_replace('}', ' } ', $data);
    $data = str_replace('[', ' [ ', $data);
    $data = str_replace('[', ' ] ', $data);
    $data = str_replace('"', ' " ', $data);
    $words = explode(' ', $data);
    foreach ($words as $key => $word) {
        if (strlen($word) > 1) {
            $words[$key] = spellcheck($word);
        }
        //if
    }
    //foreach
    $data = implode(' ', $words);
    $data = str_replace(' $ ', '$', $data);
    $data = str_replace(' ? ', '?', $data);
    $data = str_replace(' ! ', '!', $data);
    $data = str_replace(' . ', '.', $data);
    $data = str_replace(' , ', ',', $data);
    $data = str_replace(' ; ', ';', $data);
    $data = str_replace(' : ', ':', $data);
    $data = str_replace(' ( ', '(', $data);
    $data = str_replace(' ) ', ')', $data);
    $data = str_replace(' { ', '{', $data);
    $data = str_replace(' } ', '}', $data);
    $data = str_replace(' [ ', '[', $data);
    $data = str_replace(' [ ', ']', $data);
    $data = str_replace(' " ', '"', $data);
    return $data;
}
<p class="compact"><strong><?php 
print _("Spellcheck suggestions:");
?>
</strong> (Falsche Vorschl&auml;ge? <a href="faq.php#spellcheck">Siehe FAQ</a>)</p>

<table cellspacing="0" cellpadding="0">
<tr>
<td valign="top">
<ul class="compact">
<?php 
$start = getmicrotime();
$w = $_GET['word'];
$arr = spellcheck($w);
$misspelled_words = 0;
foreach ($arr as $subArray) {
    foreach ($subArray as $term) {
        $misspelled_words++;
        # this query looks strange, but it's faster than
        # "words.word = '%s' OR words.lookup = '%s'":
        # Currently commented out because we link all words, even those that
        # are not in OpenThesaurus:
        /*$query = sprintf("
        			SELECT meanings.id
        			FROM word_meanings, words, meanings
        			WHERE 
        				words.id = word_meanings.word_id AND
        				word_meanings.meaning_id = meanings.id AND
        				meanings.hidden = 0 AND
        				words.word = '%s'
        						
        			UNION 
Пример #3
0
<?php

/*
 $Id: spellcheck.php,v 1.1 2004/02/16 14:35:19 tim Exp $
 http://www.bagley.org/~doug/shootout/
*/
//(with some modifications by tim)
//the data is from /usr/dict/words
function spellcheck()
{
    $datafile = $_ENV["PCC_HOME"] . "/benchmarks/data/spellcheck";
    if (!file_exists($datafile)) {
        trigger_error("Couldn't find datafile {$datafile}.", E_USER_ERROR);
    }
    $dict = array();
    $fd = fopen($datafile, "r");
    while (!feof($fd)) {
        $dict[chop(fgets($fd, 1024))] = 1;
    }
    fclose($fd);
    $fd = fopen($datafile, "r");
    while (!feof($fd)) {
        $word = chop(fgets($fd, 1024));
        if (!$dict[$word]) {
            print "{$word}\n";
        }
    }
    fclose($fd);
}
spellcheck();
Пример #4
0
    	$i=0; $offset=0; unset ($words_start_pos);
    	foreach ($words as $value) 
    		{
    		$words_start_pos[$i] = strpos($_SESSION["first_time_text"], $value, $offset);
    		$offset = $words_start_pos[$i]+ strlen($value);
    		$i++;
    		}
    */
    unset($words_start_pos);
    $words = array();
    $words_start_pos = array();
    //return by var arrays $words, $words_start_pos :take respect of $black_holes
    parseWords($_SESSION["first_time_text"], $black_holes, $words, $words_start_pos);
    $_SESSION["words"] = $words;
    $_SESSION["words_start_pos"] = $words_start_pos;
    $_SESSION["misspelled"] = spellcheck($words);
    $_SESSION["temp_corrected"] = $_SESSION["first_time_text"];
    $_SESSION["correct_pos"] = 0;
}
//Some debug. Uncoment to test
/*
print("words\n");
print("<PRE>\n");
print_r($_SESSION["words"]);
print("</PRE>\n");
print("####\n\n");


print("starting positions\n");
print("<PRE>\n");
print_r($_SESSION["words_start_pos"]);
Пример #5
0
	<td align="right"><strong>Suggestions</strong></td>
</tr>
</tr>
	<?php 
while ($db->next_record()) {
    $query2 = sprintf("SELECT word, meaning_id\n\t\t\tFROM word_meanings, words, meanings\n\t\t\tWHERE \n\t\t\t\twords.word = '%s' AND\n\t\t\t\twords.id = word_meanings.word_id AND\n\t\t\t\tword_meanings.meaning_id = meanings.id AND\n\t\t\t\tmeanings.hidden = 0\n\t\t\t\tLIMIT 1", addslashes($db->f('term')));
    $db2->query($query2);
    if ($db2->nf() > 0) {
        continue;
    }
    if ($i % 2 == 0) {
        $col = ' bgcolor="#eeeeee"';
    } else {
        $col = "";
    }
    $sugg = spellcheck($db->f('term'));
    if (sizeof($sugg) == 0) {
        # no typo
        continue;
    }
    ?>
		<tr<?php 
    print $col;
    ?>
>
			<td align="right"><?php 
    print $i + 1;
    ?>
</td>
			<td><?php 
    print $db->f('date');