【问题标题】:Check with php if two phrases contain the same word用 php 检查两个短语是否包含相同的单词
【发布时间】:2017-12-26 12:37:45
【问题描述】:

我想检查两个短语是否包含 same word 与 PHP 我正在使用 strpos 和 strstr 但不适用于我,因为我不知道确切的词的位置。

example :

Thismyfirstword
checkfirstmore

在两个词中,有一个词'first'表示它是真的。

你有什么想法吗?

更多解释

我有两个 table,我很好地做 loup 来检查一个短语是否包含像这样的相同单词:

  1. 表一包含:

    wordone - thatistrue- youknowho- mynamesis - moreexmple - Thismyfirstword

  2. 表二包含:

这里什么都没有 - checkfirstmore - thatwatineed -moremore- younameslike

结果

Thismyfirstword = checkfirstmore (first)

mynamesis = younameslike (names)

moreexmple = 更多(更多

【问题讨论】:

  • 你将如何首先从两个字符串中识别一个单词?我的意思是有什么具体规定吗?
  • 您的问题不清楚,能否分享您的尝试和所需的输出?
  • 好的,我现在就解释,谢谢
  • 您好,我解释一下,请检查问题否是表格生成器自动的最小长度
  • moreexmplemoremore 怎么样?

标签: php mysql text


【解决方案1】:

我认为这就是您要寻找的。如您在评论中提到的,如果两者都有一些最小长度 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";
    }

【讨论】:

    【解决方案2】:
    strpos($string1, 'first');
    

    如果返回 0 或大于 0 则表示单词匹配。

    否则,不匹配

    if(strpos($string1, 'first') > -1){
        echo "Found";
    }else{
        echo "Not Found";
    }
    

    所以你也可以检查 string2。

    【讨论】:

    • 我不知道第一个词是我有两个表的问题,我需要做这个测试
    • 问题不清楚,因为如何从Thismyfirstword checkfirstmore知道这两个字符串
    • 将两个字符串都转换为数组。对 2 个数组使用 array_intersect,如果你得到结果,则意味着你有一些共同点,否则没有。
    • 好吧,我们可以在这里给出提示,休息他可以根据自己的需要进行优化。
    • 你好,我解释一下,请检查问题
    猜你喜欢
    • 1970-01-01
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    相关资源
    最近更新 更多