您可以使用similar_text 进行比较。唯一的问题是可比性因素似乎是任意的。
<?php
$array1 = array("http://example.com/abc","http://google.com/xyz","http://yahoo.com/abc", "http://stackoverflow.com/mnr");
$array2 = array("http://example.com/xyz","http://w3schools.com/xyz","http://stackoverflow.com/abc");
print_r($array1);
print_r($array2);
echo "\n";
foreach ($array1 as $slice)
{
foreach ($array2 as $slice2)
{
echo 'Comparing '.$slice.' to '.$slice2.' gives comparability of '.similar_text($slice,$slice2)."\n";
if (similar_text($slice,$slice2) > 18)
{
echo $slice.' ____is similar to___ '.$slice2."\n";
}
}
}
?>
输出:
Comparing http://example.com/abc to http://example.com/xyz gives comparability of 19
http://example.com/abc ____is similar to___ http://example.com/xyz
Comparing http://example.com/abc to http://w3schools.com/xyz gives comparability of 13
Comparing http://example.com/abc to http://stackoverflow.com/abc gives comparability of 17
Comparing http://google.com/xyz to http://example.com/xyz gives comparability of 17
Comparing http://google.com/xyz to http://w3schools.com/xyz gives comparability of 18
Comparing http://google.com/xyz to http://stackoverflow.com/abc gives comparability of 14
Comparing http://yahoo.com/abc to http://example.com/xyz gives comparability of 13
Comparing http://yahoo.com/abc to http://w3schools.com/xyz gives comparability of 15
Comparing http://yahoo.com/abc to http://stackoverflow.com/abc gives comparability of 18
Comparing http://stackoverflow.com/mnr to http://example.com/xyz gives comparability of 14
Comparing http://stackoverflow.com/mnr to http://w3schools.com/xyz gives comparability of 16
Comparing http://stackoverflow.com/mnr to http://stackoverflow.com/abc gives comparability of 25
http://stackoverflow.com/mnr ____is similar to___ http://stackoverflow.com/abc
因此,您可以将匹配项放在一个数组中并在之后输出。