0

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.

3
Contributors
7
Replies
8
Views
4 Years
Discussion Span
Last Post by HelloJarvis
4

@HelloJarvis

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.

I'm not sure why you double again? You shouldn't do that. I can tell you most likely this question you ask will be not answer. It's not being rude. I have seen this a few times and the end result is being ignore. It's very rude for you, to post a question twice and expect someone to help you in one thread and on the other thread different a person is helping you with the same issue? That's a lot of confusion.

http://www.daniweb.com/web-development/php/threads/440628/php-request-freezing-only-when-i-try-to-strip-whitespace

0

Give an example of the input that does not work. I cannot reproduce your problem.

Edited by pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.