Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP : search for a string within a string

I want to check whether a string is present in another string, and then take the appropriate action. What is the best way to do this?

For instance; if the string 'europe' is present in 'europeisthebest', then do something.

if ( isIn('europe', 'europeisthebest') == true){
  //do something
}

Thank you a lot! I appreciate all of your answers and time spent helping.

like image 561
inrob Avatar asked Sep 20 '25 09:09

inrob


1 Answers

You're looking for strstr() (case sensitive), stristr() (case insenstive), or strpos()

if (stristr('europeisthebest', 'europe')){
  // do something
}
like image 59
John Conde Avatar answered Sep 23 '25 00:09

John Conde