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.

Recommended Answers

All 7 Replies

Member Avatar for LastMitch

@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

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

For instance, if you tried "hello;" instead of "hello"

Weird, maybe it's because I'm executing this through an Ajax request?

Weird. Why might it be failing? I can post my full code if need be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.