Problem with a function :/

Discussion in 'PHP' started by misterdh, Jul 8, 2010.

  1. #1
    Hi

    I have a problem with this code. The problem is that it only redirect when I ONLY write "word" in the text field. I want it to redirect whenever "word" is submitted even if there is other characters in the textfield.

    Is there any code that tells it that it will trigger whenever it finds that array in the text field?

    function wordsExist(&$string, $words) {
        foreach($words as &$word) {
            if(stripos($string, $word) !== false) {
                return true;
            }
        }
        return false;
    }
    
    if (wordsExist($search, array('word'))) {
        $redir = $search;
    }
    
    PHP:

    Thanks in advance :)
     
    misterdh, Jul 8, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    I think you need to use
    in_array
    PHP:
     
    MyVodaFone, Jul 8, 2010 IP
  3. Artifactal Connection

    Artifactal Connection Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    function wordsExist ($string, $words) {
        foreach ($words as $word) {
            if (strpos($string, $word) == true) {
                return true;
            } else {
                continue;
            }
    }
    
    if (wordsExist($search, array('word'))) {
        $redir = $search;
    }
    PHP:
     
    Last edited: Jul 8, 2010
    Artifactal Connection, Jul 8, 2010 IP
  4. misterdh

    misterdh Peon

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    MyVodaFone: in_array didnt work... The thing is that it works perfectly when I type "word".. But if I type "word word2" then it doesnt .. I want it to work when it detects "word" even if there is other words as well ..

    Artifactial Connection: Left me with a blank page :(
     
    misterdh, Jul 8, 2010 IP
  5. Artifactal Connection

    Artifactal Connection Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Should work now - missed one typo :)
     
    Artifactal Connection, Jul 8, 2010 IP