从 URL 获取片段(散列“#"后的值) [英] Get fragment (value after hash '#') from a URL

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

问题描述

如何使用 PHP 选择 URL 中#"符号后的片段?
我想要的结果是photo45".

How can i select the fragment after the '#' symbol in my URL using PHP?
The result that i want is "photo45".

这是一个示例网址:
http://example.com/site/gallery/1#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,mck89 的回答 非常好.

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

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

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