2011-03-11 74 views
1

有一个问题在这些地方

$_SERVER['REQUEST_URI'] 

被吐出: /dev/nava2/store/index.php?route=product/product&product_id=48

实际的URL /dev/nava2/store/index.php?route=product/product&product_id=48

很明显,区别在于顶部的&与底部的&

full co de看起来像这样:

$currentpage = $_SERVER['REQUEST_URI']; 
$classic = "/dev/nava2/store/index.php?route=product/product&product_id=48"; 


if ($currentpage == $classic) 
    { $classicclass = "current"; 

    } 

else { echo "";} 

有什么建议吗?

回答

4

&是对应于&的html实体。您可以获取到初始字符串与html_entity_decode

$original = html_entity_decode($_SERVER['REQUEST_URI']); 
+0

这个伎俩!感谢将在5标记为正确。 – 2011-03-11 20:49:02

+0

并且url不应该包含'&'而是'&',然而大多数浏览器/ web服务器将会努力纠正用户输入...参见[w3c附录B:§B.2.2](http ://www.w3.org/TR/html4/appendix/notes.html#hB.2.2)。 – 2012-10-27 13:00:26

1
echo html_entity_decode($_SERVER['REQUEST_URI']); 
+0

这不会工作,根据http://php.net/manual/en/function.urldecode.php urldecode只解码%##编码。 – krtek 2011-03-11 20:46:59

+0

@Krtek - 你是对的 - 编辑。 – DeaconDesperado 2011-03-11 20:55:11

+0

谢谢你的尝试。看起来我们都学到了一些东西! – 2011-03-11 20:58:50

1

您可以使用html_entity_decode()获得实际的URL,但最上面的一个应该工作。我不认为你需要改变任何事情。如果你真的需要改变你的uri的某些部分,你也可以使用str_replace或preg_replace。