从PHP中的URL获取片段(哈希值“#"后的值) [英] Get fragment (value after hash '#') from a URL in php
问题描述
如何从php中的URL获取片段(哈希值#"后的值)?
How can I get the fragment (value after hash '#') from a URL in php?
从http://domain.com/site/gallery/1#photo45
说我要photo45
推荐答案
如果要在用户浏览器中显示的哈希标记或锚点之后获取该值:使用标准" HTTP作为此值是不可能的永远不会发送到服务器(因此在$_SERVER["REQUEST_URI"]
或类似的预定义变量中将不可用).您可能需要在客户端使用某种JavaScript魔术,例如将该值作为POST参数添加.
If you want to get the value after the hash mark or anchor as shown in a user's browser: This isn't possible with "standard" HTTP as this value is never sent to the server (hence it won't be available in $_SERVER["REQUEST_URI"]
or similar predefined variables). You would need some sort of JavaScript magic on the client side, e.g. to include this value as a POST parameter.
If it's only about parsing a known URL from whatever source, the answer by mck89 is perfectly fine though.
这篇关于从PHP中的URL获取片段(哈希值“#"后的值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!