<?php
// pspell_test.php
// RJM Programming
// September, 2024
// Thanks to https://www.php.net/manual/en/function.pspell-check.php
$results='';
if (isset($_GET['testwords']) || isset($_POST['testwords'])) {
$pspell = pspell_new("en");

if (pspell_check($pspell, "" . (isset($_GET['testwords']) ? str_replace('+',' ',urldecode($_GET['testwords'])) : '') . (isset($_POST['testwords']) ? str_replace('+',' ',urldecode($_POST['testwords'])) : ''))) {
    $results="" . (isset($_GET['testwords']) ? str_replace('+',' ',urldecode($_GET['testwords'])) : '') . (isset($_POST['testwords']) ? str_replace('+',' ',urldecode($_POST['testwords'])) : '') . " ... This is a valid spelling";
} else {
    $results="" . (isset($_GET['testwords']) ? str_replace('+',' ',urldecode($_GET['testwords'])) : '') . (isset($_POST['testwords']) ? str_replace('+',' ',urldecode($_POST['testwords'])) : '') . " ... Sorry, wrong spelling";
}
}
echo "<html>
<head>
<title>Try out Pspell - RJM Programming - September, 2024</title>
</head>
<body>
<h1>Try out Pspell for English</h1>
<h3>RJM Programming - September, 2024</h3>
<h4>Thanks to <a target=_blank href='//www.php.net/manual/en/function.pspell-check.php'>php.net</a></h4>
<div id=results>" . $results . "</div><br>
<br>
<form action=./pspell_test.php method=POST>
<textarea style=width:80%; data-type=text name=testwords id=words placeholder='Type in your word to check the spelling, regarding ...' value=''></textarea>
<br><br><input type=submit value=Check></input>
</form>
</body>
</html>";
?>
