{"id":64761,"date":"2024-09-22T03:01:00","date_gmt":"2024-09-21T17:01:00","guid":{"rendered":"https:\/\/www.rjmprogramming.com.au\/ITblog\/?p=64761"},"modified":"2024-10-01T19:58:13","modified_gmt":"2024-10-01T09:58:13","slug":"php-pspell-extension-sentence-spell-checker-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-pspell-extension-sentence-spell-checker-tutorial\/","title":{"rendered":"PHP Pspell Extension Sentence Spell Checker Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php\" rel=\"noopener\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP Pspell Extension Sentence Spell Checker Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_more.gif\" title=\"PHP Pspell Extension Sentence Spell Checker Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">PHP Pspell Extension Sentence Spell Checker Tutorial<\/p><\/div>\n<p>Thinking on how to progress from yesterday&#8217;s <a title='PHP Pspell Extension Word Spell Checker Primer Tutorial' href='#phppewscpt'>PHP Pspell Extension Word Spell Checker Primer Tutorial<\/a> start &#8230;<\/p>\n<ul>\n<li>An English sentence is just word(s).<\/li>\n<li>An English sentence involves punctuation.<\/li>\n<li>An English sentence might include &#8220;numerical words&#8221;.<\/li>\n<\/ul>\n<p> &#8230; are all valid considerations, the first the clue to how we progress from &#8220;a single word&#8221; scenario to a &#8220;looping through the sentence word(s)&#8221; scenario that is the major step forward, the other two being &#8220;the constraints&#8221; <font size=1>(within the remit of your project plan)<\/font> if you will, or the niceties <font size=1>(if attended to)<\/font>, regarding improving <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php-GETME\" rel=\"noopener\">our changed<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php-GETME\" rel=\"noopener\">second draft<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php\" rel=\"noopener\">small PHP Pspell Sentence Checker web application<\/a> you can <a href='#ifpspell'>also try below<\/a> &#8230;<\/p>\n<p><code><br \/>\n&lt;?php<br \/>\n\/\/ pspell_test.php<br \/>\n\/\/ RJM Programming<br \/>\n\/\/ September, 2024<br \/>\n\/\/ Thanks to https:\/\/www.php.net\/manual\/en\/function.pspell-check.php<br \/>\n$results='';<br \/>\n$prefix='';<br \/>\n$midbit='';<br \/>\n$lb='';<br \/>\n$suffix='';<br \/>\n$cstring=\" ... This is a valid spelling\";<br \/>\n$wstring=\" ... Sorry, wrong spelling\";<br \/>\nif (isset($_GET['testwords']) || isset($_POST['testwords'])) {<br \/>\n$pspell = pspell_new(\"en\");<br \/>\n$sentence=str_replace(\"\u2019\",\"'\",('' . trim(\"\" . (isset($_GET['testwords']) ? str_replace('+',' ',urldecode($_GET['testwords'])) : '') . (isset($_POST['testwords']) ? str_replace('+',' ',urldecode($_POST['testwords'])) : ''))) . '');<br \/>\n$origwords=explode(' ',trim($sentence));<br \/>\n$sentence=str_replace(\"\u2019\",\"'\",str_replace('~','',str_replace('?~','',str_replace('!~','',str_replace('.~','',('' . trim(\"\" . (isset($_GET['testwords']) ? str_replace('+',' ',urldecode($_GET['testwords'])) : '') . (isset($_POST['testwords']) ? str_replace('+',' ',urldecode($_POST['testwords'])) : ''))) . '~')))));<br \/>\n$words=explode(' ',trim($sentence));<br \/>\n$finalwords=explode(' ',trim($sentence));<br \/>\n$fwords=explode(' ',trim($sentence));<br \/>\nif (sizeof($words) &gt; 1) {<br \/>\n  $results='&lt;table style=\"border:1px dotted pink;\"&gt;&lt;tr&gt;&lt;td&gt;';<br \/>\n  $suffix='&lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;';<br \/>\n  $lb='&lt;br&gt;';<br \/>\n  $midbit='&lt;\/td&gt;&lt;td&gt;';<br \/>\n  $cstring='&amp;#10004;';<br \/>\n  $wstring='&amp;#10060;';<br \/>\n}<br \/>\n<br \/>\nfor ($jj=0; $jj&lt;sizeof($words); $jj++) {<br \/>\n$finalwords[$jj]='';<br \/>\n$fwords[$jj]='';<br \/>\nfor ($kk=0; $kk&lt;strlen($words[$jj]); $kk++) {<br \/>\n  if (substr(substr($words[$jj],$kk),0,1) &gt;= '0' && substr(substr($words[$jj],$kk),0,1) &lt;= '9') {<br \/>\n    $finalwords[$jj].=substr(substr($words[$jj],$kk),0,1);<br \/>\n  } else if (strtolower(substr(substr($words[$jj],$kk),0,1)) &gt;= 'a' && strtolower(substr(substr($words[$jj],$kk),0,1)) &lt;= 'z') {<br \/>\n    $finalwords[$jj].=substr(substr($words[$jj],$kk),0,1);<br \/>\n    $fwords[$jj].=substr(substr($words[$jj],$kk),0,1);<br \/>\n  } else if (substr(substr($words[$jj],$kk),0,1) == '-') {<br \/>\n    $finalwords[$jj].=substr(substr($words[$jj],$kk),0,1);<br \/>\n    $fwords[$jj].=substr(substr($words[$jj],$kk),0,1);<br \/>\n  } else if (substr(substr($words[$jj],$kk),0,1) == \"'\" && $kk != 0 && $kk != (-1 + strlen($words[$jj]))) {<br \/>\n    $finalwords[$jj].=substr(substr($words[$jj],$kk),0,1);<br \/>\n    $fwords[$jj].=substr(substr($words[$jj],$kk),0,1);<br \/>\n  }<br \/>\n}<br \/>\nif (pspell_check($pspell,  $finalwords[$jj]     ) || $fwords[$jj] == '' || is_numeric('' . $fwords[$jj])) {<br \/>\n    $results.=\"\" . $origwords[$jj] . $lb . $cstring;<br \/>\n} else {<br \/>\n    $results.=\"\" . $origwords[$jj] . $lb . $wstring;<br \/>\n    $suggestions = pspell_suggest($pspell, \"\" . $words[$jj]);<br \/>\n    $results.=\"&lt;br&gt;&lt;br&gt;\";<br \/>\n    $ii=0;<br \/>\n    foreach ($suggestions as $suggestion) {<br \/>\n        if (strpos($results, '&lt;select') === false) {<br \/>\n          $ii=2;<br \/>\n          $results.='&lt;select size=2&gt;&lt;option value=\"\"&gt;Possible spelling ...&lt;\/option&gt;&lt;\/select&gt;';<br \/>\n        } else {<br \/>\n          $ii++;<br \/>\n        }<br \/>\n        $results=str_replace('&lt;\/select&gt;', '&lt;option value=\"' . $suggestion . '\"&gt;' . $suggestion . '&lt;\/option&gt;&lt;\/select&gt;', $results);<br \/>\n    }<br \/>\n    if ($ii &gt; 0) {<br \/>\n        $results=str_replace('&lt;select', '&lt;select onclick=\"if (this.size != ' . $ii . ') { this.size=' . $ii . ';  }\" ', $results);<br \/>\n    }<br \/>\n}<br \/>\n$results=str_replace('&lt;\/select&gt;', '&lt;\/SELECT&gt;', str_replace('&lt;select', '&lt;SELECT', $results));<br \/>\n$results.=$midbit;<br \/>\n}<br \/>\n$results.=$suffix;<br \/>\n}<br \/>\necho \"&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;style&gt;<br \/>\n  td {<br \/>\n    vertical-align: top;<br \/>\n  }<br \/>\n&lt;\/style&gt;<br \/>\n&lt;title&gt;Try out Pspell - RJM Programming - September, 2024&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;h1&gt;Try out Pspell for English&lt;\/h1&gt;<br \/>\n&lt;h3&gt;RJM Programming - September, 2024&lt;\/h3&gt;<br \/>\n&lt;h4&gt;Thanks to &lt;a target=_blank href='\/\/www.php.net\/manual\/en\/function.pspell-check.php'&gt;php.net&lt;\/a&gt;&lt;\/h4&gt;<br \/>\n&lt;div id=results&gt;\" . $results . \"&lt;\/div&gt;&lt;br&gt;<br \/>\n&lt;br&gt;<br \/>\n&lt;form action=.\/pspell_test.php method=POST&gt;<br \/>\n&lt;textarea style=width:80%; data-type=text name=testwords id=words placeholder='Type in your word(s) to check the spelling, regarding ...' value=''&gt;&lt;\/textarea&gt;<br \/>\n&lt;br&gt;&lt;br&gt;&lt;input type=submit value=Check style=background-color:yellow;&gt;&lt;\/input&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;\";<br \/>\n?&gt;<br \/>\n<\/code><\/p>\n<p><b><i>Stop Press<\/i><\/b><\/p>\n<p>We realized, after the work above, multiple correcting dropdown suggestion lists were not happening, and we remedied this with <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php--GETME\" rel=\"noopener\">our changed<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php--GETME\" rel=\"noopener\">third draft<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php\" rel=\"noopener\">small PHP Pspell Sentence Checker web application<\/a>, here on October 1, after saying &#8220;rabbits&#8221;.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=\"_blank\" href='\/\/www.rjmprogramming.com.au\/ITblog\/new-php-pspell-extension-word-spell-checker-primer-tutorial\/' rel=\"noopener\">New PHP Pspell Extension Word Spell Checker Primer Tutorial<\/a>.<\/p-->\n<hr>\n<p id='phppewscpt'>Previous relevant <a target=\"_blank\" title='PHP Pspell Extension Word Spell Checker Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php-pspell-extension-word-spell-checker-primer-tutorial\/' rel=\"noopener\">PHP Pspell Extension Word Spell Checker Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php\" rel=\"noopener\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP Pspell Extension Word Spell Checker Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.gif\" title=\"PHP Pspell Extension Word Spell Checker Primer Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">PHP Pspell Extension Word Spell Checker Primer Tutorial<\/p><\/div>\n<p>We&#8217;re interested in Spell Checking, and saw an extension called <a target=\"_blank\" title='Pspell' href='https:\/\/github.com\/php\/pecl-text-pspell' rel=\"noopener\">Pspell<\/a> &#8230; installed here (for PHP 8.1 purposes) on AlmaLinux via &#8230;<\/p>\n<p><code><br \/>\ndnf install ea-php81-php-pspell.x86_64<br \/>\n<\/code><\/p>\n<p> &#8230; which helps out in this regard, us just starting with &#8230;<\/p>\n<ul>\n<li>English<\/li>\n<li>single word<\/li>\n<\/ul>\n<p> &#8230; analysis in this <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php_GETME\" rel=\"noopener\">first draft<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php\" rel=\"noopener\">Single English word spell checker<\/a> you can also try below &#8230;<\/p>\n<p><iframe id=ifpspell src=\"\/\/www.rjmprogramming.com.au\/PHP\/pspell_test.php\" style=\"width:100%;height:600px;\"><\/iframe><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d64756' onclick='var dv=document.getElementById(\"d64756\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/spell-checker\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d64756' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d64761' onclick='var dv=document.getElementById(\"d64761\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/sentence\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d64761' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Thinking on how to progress from yesterday&#8217;s PHP Pspell Extension Word Spell Checker Primer Tutorial start &#8230; An English sentence is just word(s). An English sentence involves punctuation. An English sentence might include &#8220;numerical words&#8221;. &#8230; are all valid considerations, &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-pspell-extension-sentence-spell-checker-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,13,37],"tags":[4843,388,1797,611,613,2205,3870,2394,1520,2181,932,997,4923,2502,1119,4921,4922,4920,1200,1319,1452],"class_list":["post-64761","post","type-post","status-publish","format-standard","hentry","category-elearning","category-esl","category-tutorials","tag-dnf","tag-english","tag-extension","tag-install","tag-installer","tag-loop","tag-looping","tag-number","tag-numerical","tag-package-manager","tag-php","tag-programming","tag-pspell","tag-punctuation","tag-sentence","tag-spell","tag-spell-checker","tag-spell-checking","tag-stop-press","tag-tutorial","tag-word"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/64761"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=64761"}],"version-history":[{"count":11,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/64761\/revisions"}],"predecessor-version":[{"id":64879,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/64761\/revisions\/64879"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=64761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=64761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=64761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}