Php 在两段文本之间查找匹配短语?

Php 在两段文本之间查找匹配短语?,php,string,recursion,logic,Php,String,Recursion,Logic,我的目标是从两篇文章中找出相似的短语 我知道常用词会成为一个问题。例如,和我们就是。在这种情况下,我认为需要一个过滤器 我想知道这是不是一个好方法?它使用递归,如果找到匹配项,它会查看下一个单词是否也是匹配项,并继续执行,直到没有匹配项为止 1. the cat is on the roof 2. a man is on the stage A1 = [the, cat, is, on, the, roof] A2 = [a, man, is, on, the, stage]

我的目标是从两篇文章中找出相似的短语

我知道常用词会成为一个问题。例如,
我们就是
。在这种情况下,我认为需要一个过滤器

我想知道这是不是一个好方法?它使用递归,如果找到匹配项,它会查看下一个单词是否也是匹配项,并继续执行,直到没有匹配项为止

  1. the cat is on the roof
  2. a man is on the stage

  A1 = [the, cat, is, on, the, roof]
  A2 = [a, man, is, on, the, stage]

  [the]: no match
  [cat]: no match
  [is]: match
  [is, on]: match
  [is, on, the]: match
  [is, on, the, roof]: no match
  [on]: match
  [on, the]: match
  [on, the, roof]: no match
  [the]: match
  [the, roof]: no match
  [roof]: no match
  -end-

在Google上快速搜索后,我看到了您问题的解决方案:

它的工作原理是找到两种语言共有的最长单词序列 字符串,并递归地查找 字符串的剩余部分,直到子字符串没有共同的单词。 在这一点上,它添加剩余的新词作为插入和 保留旧单词作为删除


你想让我们对方法提出建议,你能展示一下代码吗,之后的方法似乎还不错