To check whether a string is a Substring of another

Discussion in 'PHP' started by subeeshkk, Jan 28, 2008.

  1. #1
    Hi all ,

    Pls hlp me , i am a beginner ,

    I want to check whether a string is substring of another string , how do i do that.....

    substr returns the substring with the given start and end , but i just need to know , whether str1 is in str2....

    Thanks in advance
     
    subeeshkk, Jan 28, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Use strpos():

    
    
    if (strpos($str2, $str1) !== false)
    {
        // str1 is in str2
    }
    
    PHP:
     
    nico_swd, Jan 28, 2008 IP