我开发了这个小代码来检查 2 个文本是否有共同词,一个来自数据库,另一个来自外部输入。问题是我收到一条消息“参数不是数组”。我看不出问题出在哪里。我还需要检查 2 条消息是否应该有相同的单词在相同的序列中。请帮助了解错误在哪里。谢谢
$checkMsg=strip_tags($_POST['checkMsg']); // message from input form
$message // message from database
$MsgWords = preg_split("/[\s,]+/", $checkMsg);
if(!empty($checkMsg)){
foreach ($MsgWords as $Neword)
{ $Neword = trim($Neword);
echo " $Neword";
}
$word = preg_split("/[\s,]+/", $message);
foreach ($word as $currentWord)
{
$currentWord = trim($currentWord);
echo " $currentWord";
}
$intersect=array_intersect( $Neword ,
$currentWord);
echo" Your common words are: $intersect";}else{echo "No common words";}