2

I'am looking for a syntax that will do the following:

if('String' not in $string){

//do this

}

I am also looking for away to say

if('String' in $string){

//do this

}

Can anyone help, I have googled for solutions and they seem very confusing.

Thanks, J

user1269625
  • 3,121
  • 26
  • 79
  • 111
  • Possible duplicat [How to check if a string contains specific words?](http://stackoverflow.com/questions/4366730/how-to-check-if-a-string-contains-specific-words). – Vucko Dec 18 '13 at 18:29

2 Answers2

7

I always use this:

if (stristr($string, "string")) {
    //String exists within $string
}else{
    //String does not exist
}

http://www.php.net/stristr

James
  • 3,765
  • 4
  • 48
  • 79
3

Try this:

if(strpos($string, 'String') !== false) {
    //string exist
}
else{
    //string not exist
}
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171