Hello everyone,
I am working on a program that is sending some input to a thesaurus API, but not after stripping any non-alphanumeric characters. This would be easy, except I want to also preserve the original non-alphanumeric characters for output; for instance, if the user sends "hello;", the request to the API may be taken as "hello", but the output will still be "hello;". Here is my code:
$sentence = $_POST["sentence"];
$words = explode(" ", $sentence);
foreach ($words as $word)
{
$sanitizedWord = trim(preg_replace("/[^a-zA-Z0-9]/", "", $word));
$file = @file_get_contents("http://words.bighugelabs.com/api/2/api_key/$sanitizedWord/");
if ($file !== FALSE)
$test = preg_split("/(\r\n|\n|\r)/", $file);
// program stuff
}
This code works beautifully for any input with all alphanumeric characters, but freezes when I try using something like a semicolon. This is getting very frustrating. Help would be greatly appreciated.