如何打印地址网址,包括#

时间:2013-08-05 07:07:01

标签: php

我想回复确切的网址:http://domain.com/mystuff.html#123456

但它只打印http://domain.com/mystuff.html如何包含#123456?所以变成http://domain.com/mystuff.html#123456

我的代码到目前为止

$urladdress =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING'];

3 个答案:

答案 0 :(得分:4)

你做不到。片段标识符完全由客户端处理,因此浏览器不会将其发送到服务器。

(最近你可能会(在页面加载后)使用JavaScript在另一个请求中将其发送到服务器。)

答案 1 :(得分:0)

你无法使用php获得它,你可以通过javascript完成它。使用此测试脚本检查结果。

<script>
alert(document.URL);

    var urlDetail = document.URL;//you can use this variable to print in your web page.
</script>

答案 2 :(得分:-1)

找到答案:

<a href="'.$urladdress.'#'.parse_url("http://domain.com?page.html#123456",PHP_URL_FRAGMENT).'">text</a>
相关问题