For 1. you should use explode(' ',$inputContents)
and you'll endup with:
{ [0]=> "Spellling" [1]=> "games;" [2]=> "they're" [3]=> "alot" [4]=> "of" [5]=> "fun!" }
Then create a new array $checkedWords=array();
and take care of 2.
foreach ($inputContents as $singleWord) {
//your MySQL checks here;
//mysql_ functions were deprecated, use mysqli or PDO instead
preg_match('/([a-zA-Z\']*)(\W*)/',$singleWord,$parts);
//check parts[0] against MySQL here
//$parts[1] is your word without other following chars
//$parts[2] are any characters following your word
if (isset($parts[2]) $parts[2]='';
if ($word_exists !== 0) {
$checkedWords[]=$parts[1].$parts[2];
}else{
$checkedWords[]="<span class='misspelledWord'>".$parts[1]."</span>".$parts[2];
}
}
To get to 4. you'll just have to implode(' ',$checkedWords)