且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 URL 获取片段(散列“#"后的值)

更新时间:2022-02-02 23:02:24

如果您想获取用户浏览器中显示的井号或锚点后的值:这是不可能的标准"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.