[英]Check with php if two phrases contain the same word
I want to check if two Phrase contain same word with PHP I'm using strpos and strstr but is not working for me because I don't know exactly the position of the word. 我想检查两个Phrase是否包含与PHP 相同的单词我使用strpos和strstr但是不适合我,因为我不确切地知道单词的位置。
example :
Thismyfirstword
checkfirstmore
In two words, there exists a word ' first ' that means it is true . 用两个词来说,有一个词“ 第一 ”意味着它是真的。
do you have any idea? 你有什么主意吗?
More Explain 更多解释
i have two table and i well make loup to check if a phrases contain the same word like this : 我有两个表 ,我很好地检查一个短语是否包含相同的单词,如下所示:
Table one containe : 表一容器:
wordone - thatistrue- youknowho- mynamesis - moreexmple - Thismyfirstword wordone - thatistrue- youknowho- mynamesis - moreexmple - Thismyfirstword
Table two containe : 表二容器:
nothinghere - checkfirstmore - thatwatineed -moremore- younameslike 无处可去 - checkfirstmore - thatwatineed -moremore- younameslike
Result 结果
Thismyfirstword = checkfirstmore ( first ) 这个myfirstword = checkfirstmore( first )
and 和
mynamesis = younameslike ( names ) mynamesis = younameslike( 名字 )
moreexmple = moremore ( more ) moreexmple = moremore( 更多 )
I think this is what you're looking for. 我想这就是你要找的东西。 It will return "TRUE" if both have some common word of minimum length 3 as you mentioned in the comment.
如果你在评论中提到的两个都有一些最小长度为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";
}
strpos($string1, 'first');
if it returns 0 or greater than 0 then it means word match. 如果它返回0或大于0则表示单词匹配。
else, not matched 否则,不匹配
if(strpos($string1, 'first') > -1){
echo "Found";
}else{
echo "Not Found";
}
So you can check for string2 too. 所以你也可以检查string2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.