从PHP中的URL获取片段(哈希值“#"后的值) [英] Get fragment (value after hash '#') from a URL in php

查看:185
本文介绍了从PHP中的URL获取片段(哈希值“#"后的值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从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.

如果仅是要解析来自任何来源的已知URL,则

If it's only about parsing a known URL from whatever source, the answer by mck89 is perfectly fine though.

这篇关于从PHP中的URL获取片段(哈希值“#"后的值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆