我正在搜索stringan 中的一组单词,array以通知用户是否找到任何单词。但是,我得到的结果并不完全匹配。关于如何让它只显示完全匹配的任何想法。我的代码如下所示。
<?php
// Profanity check
$profaneReport = "";
$allContent = "Rice Beans Class stite";
$profanity_list = "lass tite able";
$profaneWords = explode( ' ', $profanity_list );
$wordsFoundInProfaneList = []; // Create words an array
//search for the words;
foreach ( $profaneWords as $profane ) {
if ( stripos( $allContent, $profane ) !== false ) {
$wordsFoundInProfaneList[ $profane ] = true;
}
}
// check if bad words were found
if ( $wordsFoundInProfaneList !== 0 ) {
$profaneReportDesc = "Sorry, your content may contain such words as " . "<strong>" . implode( ", ", array_keys( $wordsFoundInProfaneList )) . '</strong>"';
} else {
$profaneReportDesc = "Good: No profanity was found in your content";
}
echo $profaneReportDesc;
?>
上面的代码返回“抱歉,您的内容可能包含诸如 lass, tite”这样的单词,当它们与中的单词不完全匹配时$allContent
天涯尽头无女友