eregi searching for multiple text in a page

Discussion in 'PHP' started by joshm, Nov 3, 2007.

  1. #1
    Hello,

    Is there shorter, more efficient way of doing this type of thing?

    if (eregi('text1', $checkSite) || eregi('text2', $checkSite) || eregi('text3', $checkSite) || ... ) {...

    As you can see it will be searching for specific pieces of text from a specified website URL ($checkSite). The code format above works but is there a way of finding multiple pieces of text in the site by only using eregi once?
     
    joshm, Nov 3, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    if (preg_match('~(text1|text2|text3|text4)~i', $checkSite))
    {
        // Match
    }
    
    PHP:
    Try to start using preg_* functions over ereg_*.

    The preg_* functions are about 6 times faster.
     
    nico_swd, Nov 3, 2007 IP
  3. joshm

    joshm Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks very much.

    Does the i mean case-insensitive? and what does ~ represent?
     
    joshm, Nov 3, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Yes, the i means case-insensitive.

    And the ~ are the pattern delimiters. instead of ~ you could also use forwad slashes, @ signs, |,.. and a lot others.

    I suggest you have a look at this.

    http://www.phpvideotutorials.com/regex/
     
    nico_swd, Nov 3, 2007 IP