PHP:在字符串中搜索字符串


PHP : search for a string within a string

我想检查另一个字符串中是否存在一个字符串,然后采取适当的操作。最好的方法是什么?

例如;如果字符串"europe"出现在"europeisestest"中,那就做点什么吧。

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

非常感谢!我感谢你所有的回答和花在帮助上的时间。

您正在查找strstr()(区分大小写)、stristr()(区分大小大小写)或strpos()

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

如果您想知道字符串中子字符串的位置,也可以使用函数strpos()