Try this, you should be able to improve on it.
if (!empty($_POST)) {
$keywords = array( 'IF', 'THEN', 'ELSE', 'ENDIF', 'AND', 'OR', 'XOR', '&&', '&', 'IS', 'NOT', 'WHERE' );
$logic = explode(' ', htmlentities ( strtoupper( trim($_POST['logic']) ) ) ) ;
foreach (array_diff( $logic, $keywords ) as $key => $value ){
echo $value .'<br />';
}
}
?>
<form method="post">
<textarea name="logic"> </textarea>
<input type="submit" />
</form>