1
我发现此解决方案规范化并匹配相同的URL,但我想知道是否有更优雅的东西,PHP不具有URL规范化功能?使用规范化/规范化匹配URL
function urlMatch($url1, $url2)
{
// parse the urls
$r1 = parse_url($url1);
$r2 = parse_url($url2);
// get the variables out of the queries
parse_str($r1['query'], $v1);
parse_str($r2['query'], $v2);
// match the domains and paths
if ($r1['host'] != $r2['host'] || $r1['path'] != $r2['path'])
return false;
// match the arrays
foreach ($v1 as $key => $value)
if (array_key_exists($key, $v2) && $value != $v2[$key])
return false;
// if we haven't returned already, then the queries match
return true;
}
重新标记添加规范化和消除规范化。在SO的上下文中,“标准化”标签是指数据库标准化。规范化更有可能吸引合适类型的专家。 – 2011-12-28 03:32:42
此功能错误!那么'schema'和'port'呢?或其他参数只存在于第二个网址? – 2011-12-28 03:37:27
我想我现在需要更优雅更正确的东西:( – 2011-12-28 03:43:38