使用php函数在字符串中搜索单词

rag*_*ghu 5 php string function

当我搜索"银行"时,它应显示以下列表中的Bank-List1,Bank-List2.

铁路列表,银行列表1,银行列表2,教育,电子商务,文章,铁路列表1.

是否有任何PHP功能可以显示?

我得到了完全匹配的输出.但这种搜索没有结果.

请帮我找到解决方案.

Han*_*nky 2

你可以使用stristr

\n\n

stristr \xe2\x80\x94 Case-insensitive strstr()

\n\n
<?php    // Example from PHP.net\n  $string = \'Hello World!\';\n  if(stristr($string, \'earth\') === FALSE) {\n    echo \'"earth" not found in string\';\n  }\n// outputs: "earth" not found in string\n?> \n
Run Code Online (Sandbox Code Playgroud)\n\n

因此,对于您的情况,如果您的列表位于名为的数组中$values

\n\n

你可以做

\n\n
foreach($values as $value)\n{\n      if(stristr($value, \'bank\') !== FALSE) \n      {\n        echo $value."<br>";\n      }\n}\n
Run Code Online (Sandbox Code Playgroud)\n