Check if a word / substring exists in a given string input.
Using strpos()
to find the position of the first occurrence of a substring in a string.
代码实现
function isContains($string, $needle)
{
return strpos($string, $needle) === false ? false : true;
}
使用样例
isContains('This is an example string', 'example'); // true
isContains('This is an example string', 'hello'); // false