"; $html[] = "
"; $html[] = ""; $html[] = ""; if(isset($_REQUEST["style"])) { $html[] = ""; } $html[] = "
\n"; $html[] = "
"; $html[] = ""; $entitiesPattern = array("'", "$", """); $entitiesReplace = array('\'', '\$', '\"'); if(isset($_REQUEST['finished'])) { /* put text back together here */ if(isset($_REQUEST['word']) && is_array($_REQUEST['word'])) { foreach($_REQUEST['word'] as $id => $value) { $_SESSION['text'][$id] = $value; } } $text = implode("", $_SESSION['text']); $html[] = "
"; $html[] = "

Setting text please be patient...

"; $html[] = "$text"; $_SESSION['text'] = null; unset($_SESSION['text']); } else if(!isset($_REQUEST['text'])) { $html[] = "
"; $html[] = " "; $html[] = ""; if(isset($_REQUEST["style"])) { $html[] = ""; } $html[] = ""; $html[] = " "; } else { $html[] = "
"; $html[] = "

## Steven's Spell Checker

"; $_SESSION['text'] = $_REQUEST['text']; sscParser($_SESSION['text']); if(!isset($ssc_lang)) { $lang = explode(",", $_SERVER["HTTP_ACCEPT_LANGUAGE"]); $ssc_lang = $lang[0]; } if(!isset($ssc_speed)) { $ssc_speed = PSPELL_FAST; } $pspell = pspell_new($ssc_lang, null, null, null, $ssc_speed); $output = array(); $error = false; $htmlStart = array("<", "&"); foreach($_SESSION['text'] as $id => $word) { if($word == "[[new]]") { $output[] = "
"; } else if(is_numeric($word[0])) { $output[] = $word; } else if(in_array($word[0], $htmlStart)) { $output[] = $word; } else { if(stristr($word, "[entity]")) { $word = convertEntity($word, $entitiesPattern, $entitiesReplace); $entity = TRUE; } else { $entity = FALSE; } if(pspell_check($pspell, $word)) { $output[] = $word; } else { $error = true; $suggestions = pspell_suggest($pspell, $word); $size = sizeof($suggestions); for($i = 0; $i < $size; $i++) { $suggestions[$i] = "'".addslashes($suggestions[$i])."'"; } $suggestions = implode(", ", $suggestions); $output[] = "\n"; $output[] = "\n"; } if($entity) { $_SESSION["text"][$id] = reconvertEntity($_SESSION["text"][$id], $entitiesPattern, $entitiesReplace); } } } $html[] = " "; $html[] = ""; $html[] = "

"; $html[] = "
"; $html[] = ""; $html[] = " Text to check: "; $html[] = implode("", $output); if(!$error) { $html[] = " \n No spelling errors found. "; } $html[] = ""; $html[] = " | "; $html[] = " "; $html[] = " Change to: "; $html[] = " "; $html[] = " Suggestions: "; $html[] = " \n"; $html[] = ""; $html[] = " "; $html[] = ""; $html[] = "
"; $html[] = "

"; $html[] = ""; $html[] = " "; } $html[] = "
"; $html[] = "
"; echo implode("\n", $html); function sscParser(&$text) { $patterns = array( "'(<[\/\!]*?[^<>]*?>)'si", "/\?/", "/\!/", "/\(/", "/\)/", "/(?:\r\n|\r|\n)/", "'(&(nbsp|#160);)'i", "'(&(quot|#34);)'i", "'(&(amp|#38);)'i", "'(&(lt|#60);)'i", "'(&(gt|#62);)'i"); $replacements = array("[ssc]\${1}\$3[ssc]", "[ssc]?[ssc]", "[ssc]![ssc]", "[ssc]([ssc]", "[ssc])[ssc]", "[ssc][[new]][ssc]", "[ssc]\${1}\$3[ssc]", "[ssc]\${1}\$3[ssc]", "[ssc]\${1}\$3[ssc]", "[ssc]\${1}\$3[ssc]", "[ssc]\${1}\$3[ssc]"); $text = preg_replace($patterns, $replacements, $text); $text = explode("[ssc]", $text); $text = array_filter($text, "nothing"); $htmlStart = array("<", "&"); $compArr = array(); foreach($text as $wordOrHTML) { if(!in_array($wordOrHTML[0], $htmlStart)) { $patterns = array("/ /", "/\./", "/,/", "/\:/", "/\"/", "/-/", "/@/", "'([0-9]+^;)'"); $replacements = array("[ssc] [ssc]", "[ssc].[ssc]", "[ssc],[ssc]", "[ssc]:[ssc]", "[ssc]\"[ssc]", "[ssc]-[ssc]", "[ssc]@[ssc]", "[ssc]\${1}\$3[ssc]"); $words = preg_replace($patterns, $replacements, $wordOrHTML); $wordsArr = explode("[ssc]", $words); foreach($wordsArr as $word) { if(stristr($word, ';') && stristr($word, '&')) { // html entity $word = str_replace("&", "[entity]&", $word); $word = str_replace(";", ";[entity]", $word); $compArr[] = $word; } else if(stristr($word, ';')) { // word contains a semicolon $semi = str_replace(";", "[ssc];[ssc]", $word); $semiArr = explode("[ssc]", $semi); foreach($semiArr as $sword) { $compArr[] = $sword; } } else { $compArr[] = $word; } } } else { $compArr[] = $wordOrHTML; } } $compArr = array_filter($compArr, "nothing"); $text = $compArr; } function nothing($string) { return (strlen($string) > 0); } function convertEntity($string, $entitiesP, $entitiesR) { $sArr = explode("[entity]", $string); $workingString = ""; foreach($sArr as $s) { $s = str_replace($entitiesP, $entitiesR, $s); $workingString .= $s; } return $workingString; } function reconvertEntity($string, $entitiesP, $entitiesR) { $sArr = explode("[entity]", $string); $string = $sArr[0] . str_replace($entitiesR, $entitiesP, $sArr[1]) . $sArr[2]; return $string; } ?>