我想检查两个Phrase是否包含与PHP 相同的单词我使用strpos和strstr但是不适合我,因为我不确切地知道单词的位置.
example :
Thismyfirstword
checkfirstmore
Run Code Online (Sandbox Code Playgroud)
用两个词来说,有一个词" 第一 "意味着它是真的.
你有什么主意吗?
更多解释
我有两个表,我很好地检查一个短语是否包含相同的单词,如下所示:
表一容器:
wordone - thatistrue- youknowho- mynamesis - moreexmple - Thismyfirstword
表二容器:
无处可去 - checkfirstmore - thatwatineed -moremore- younameslike
结果
这个myfirstword = checkfirstmore(第一)
和
mynamesis = younameslike(名字)
moreexmple = moremore(更多)
我想这就是你要找的东西.如果你在评论中提到的两个都有一些最小长度为3的常用词,它将返回"TRUE" .
$str1 = "Crazyworld";
$str2 = "Helloworld";
echo "This is ".check($str1, $str2);
function check($string1, $string2)
{
for($i = 0; $i <= strlen($string1) - 3; $i++)
{
$sub = substr($string1, $i, 3);
if(strpos($string2, $sub) !== false){
return "TRUE";
}
}
return "FALSE";
}
Run Code Online (Sandbox Code Playgroud)