Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中找到2个不同的字符串(string1或string2)_Php_Html - Fatal编程技术网

如何在php中找到2个不同的字符串(string1或string2)

如何在php中找到2个不同的字符串(string1或string2),php,html,Php,Html,返回整数(如果找到字符串,则返回位置),如果未找到字符串,则返回false。那你的测试呢 if(strpos($input, '[key1]') === true or strpos($input, 'key2') === true) 将永远不会通过,因为整数或false永远不会是==true。相反,请更改测试以检查strpos的结果是否为false: if(strpos($input, '[key1]') !== false or strpos($input, 'key2') !== fal

返回整数(如果找到字符串,则返回位置),如果未找到字符串,则返回
false
。那你的测试呢

if(strpos($input, '[key1]') === true or strpos($input, 'key2') === true)
将永远不会通过,因为整数或
false
永远不会是
==true
。相反,请更改测试以检查
strpos
的结果是否为
false

if(strpos($input, '[key1]') !== false or strpos($input, 'key2') !== false)

等等,那么如何找到字符串呢?@TunkuSalim你的问题并没有说任何关于找到字符串的事情,只说它是否存在not@mickmackusa这不是代表的问题,而是帮助人们的满足感。请帮助人们找到预先存在的答案。现在太晚了,我明白了。