what's the function to check if string contains a specific value

Discussion in 'PHP' started by x0x, Sep 17, 2008.

  1. #1
    Something exactly like the LIKE '%word%' in mysql.

    If $stuff contains 'lala' then bla bla

    Guess you got what I mean. :)
     
    x0x, Sep 17, 2008 IP
  2. Shoro

    Shoro Peon

    Messages:
    143
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if (strpos($stuff,'word') !== false) {
      //Do stuff
    }
    PHP:
     
    Shoro, Sep 17, 2008 IP
  3. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    thank you.
     
    x0x, Sep 17, 2008 IP
  4. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #4
    is there a non case sensitive version too?
     
    x0x, Sep 17, 2008 IP
  5. lui2603

    lui2603 Peon

    Messages:
    729
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #5
    preg_match("/$search/i", $string);
    the i makes it case insensitive
    will return true is its found
     
    lui2603, Sep 17, 2008 IP
  6. Shoro

    Shoro Peon

    Messages:
    143
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes. Just replace strpos with stripos
     
    Shoro, Sep 17, 2008 IP