我有一个代码,我使用以下函数将用逗号分隔的单词与文本匹配str_ireplace()
:
$words = "word1, word2, word3";
$text = "This is word1 text word2";
if (str_ireplace(explode(', ', $words), '', $text) != $text) {
/*Логика*/
}
你能告诉我如何做反向逻辑吗?那些。如果没有找到或匹配。
else {}
不起作用。
谢谢!
我有一个代码,我使用以下函数将用逗号分隔的单词与文本匹配str_ireplace()
:
$words = "word1, word2, word3";
$text = "This is word1 text word2";
if (str_ireplace(explode(', ', $words), '', $text) != $text) {
/*Логика*/
}
你能告诉我如何做反向逻辑吗?那些。如果没有找到或匹配。
else {}
不起作用。
谢谢!
为什么它有效,你怎么不呢?阅读手册https://www.php.net/manual/ru/function.str-ireplace
如您所见,返回类型,
string|array
即事实上mixed
,没有显式转换为 typestring
,解释器不理解您拥有什么样的返回类型并且无法正确比较。