作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个表值,如下字符串:
PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92
我得到如下随机/随机顺序的值,以验证它们是否与表值完全匹配:
PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92
or
PhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8E
or
PhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8F
or
PhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8E
or
PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60
尝试过:
select *from table1 where preview like '%PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60%' limit 1;
但这不是正确的SQL,输入值是随机的,在数据库值固定的情况下进行打乱,我需要将随机的打乱输入与固定数据库值匹配。如何使其非常稳定?
最佳答案
实现此目的的一种方法是将传入字符串拆分为单独的地址,然后检查它们是否全部与表值匹配:
$string = 'PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92';
$components = str_split($string, 33);
$query = "SELECT *
FROM table1
WHERE preview LIKE '%" . implode("%'\n AND preview LIKE '%", $components) . "%'";
echo $query;
输出:
SELECT *
FROM table1
WHERE preview LIKE '%PhysicalAddress:E8-6A-64-DE-48-60%'
AND preview LIKE '%PhysicalAddress:04-EA-56-08-E6-8E%'
AND preview LIKE '%PhysicalAddress:04-EA-56-08-E6-8F%'
AND preview LIKE '%PhysicalAddress:06-EA-56-08-E6-8E%'
AND preview LIKE '%PhysicalAddress:04-EA-56-08-E6-92%'
关于php - 如何将一个字符串与另一个字符串值精确匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57619729/
我是一名优秀的程序员,十分优秀!