gpt4 book ai didi

PHP:比较两个字符串是否存在两个相同的单词

转载 作者:可可西里 更新时间:2023-11-01 00:34:20 24 4
gpt4 key购买 nike

我需要创建一个根据比较结果返回 true 或 false 的函数。

我有两个字符串:

$one = 'sample product - White - Large'; // White is separate key, and large is separate too
$two = 'White Large';

您知道完成该任务的任何快速方法吗?分解两个字符串可能不安全,因为一些字符串而不是 White 将具有:Blue - Black - Large。所以我正在寻找 Blue - Black 的存在。

我的数据的另一个例子是:

$one = 'sample product - White - Blue - Large';  // White - Blue is separate key, Large is separate too.

如果有人对此有任何想法,我将不胜感激。

谢谢,艾洛伦

最佳答案

我会采用这样的策略:

  1. 通过空格将字符串分解为数组(使用正则表达式)
  2. 使用array_intersect()寻找匹配项

关于PHP:比较两个字符串是否存在两个相同的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13027088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com