The parse_url() function dissect the URL completely. Try the following PHP code.
<?php $url = 'http://username:password@hostname/path?arg=value#anchor'; // Print all components of the parsed url print_r(parse_url($url)); // Get the anchor part echo parse_url($url, PHP_URL_FRAGMENT); ?>
You will get an array as follow.
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
And the echo parse_url($url, PHP_URL_FRAGMENT) will return “anchor”. For more information, please refer to the PHP doc.
PHP: parse_url – Manual
The following post make use of both client side and sever side programming to store the anchor in cookie and i think it is quite inspiring. Take a look if you are interested.
stoimen’s web log – Read The Anchor Part of The URL … with PHP
Done =)

U used a string as the URi. how to get the URI dynamically ?
$_SERVER[‘REQUEST_URI’] does not include the # part.
LikeLike
There is no way to get the # part (anchor) of the URI in PHP. you have to do it together with Javascript.
please refer to the stoimen’s web log – Read The Anchor Part of The URL … with PHP
LikeLike