inrob
inrob

Reputation: 5089

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.

Upvotes: 4

Views: 6564

Answers (2)

DanielX2010
DanielX2010

Reputation: 1908

You can also use the function strpos() if you wish to know the position of the substring inside the string

Upvotes: 0

John Conde
John Conde

Reputation: 219834

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

if (stristr('europeisthebest', 'europe')){
  // do something
}

Upvotes: 12

Related Questions