Search for a string in a variable---

Discussion in 'PHP' started by cancer10, May 8, 2007.

  1. #1
    Search for a string in a variable---

    Is there a way to find a particular string in php.

    For example:

    I want php to echo "Found" if the word "sports" in found in this url http://yahoo.com/sports/soccer/index.html

    if not then it should echo "bad Luck"


    Is there any pre-defined function for this in php?


    Thanx
     
    cancer10, May 8, 2007 IP
  2. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #2
    
    $string = "http://yahoo.com/sports/soccer/index.html";
    $find   = "sports";
    
    if(strpos($string, $find) === false)
    {
        echo "Bad Luck";
    }
    else
    {
        echo "Found";
    }
    
    PHP:
     
    SoKickIt, May 8, 2007 IP