PHP - 如何获取URL字符串的最后一段[重复]

I'm trying to extract the last segment of this URL: http://test.com/blog/#segmentIwant (the #segmentIwant is the string I want). The hash tag is generated from a link within the website. Any help is much appreciated!

</div>

Well while you load a page with # tag, php does not know it as # tags on url are treated by basically javascript and are not sent to server. But with a simple AJAX request you can send the value to server on loading the page and get the response through that AJAX response.

To grab the url with Javascript:

var url = document.URL;

And try basename() function to get the last part of the sent url with PHP code.

 echo basename( "http://test.com/blog/#segmentIwant" );

Or a simple function in javascript to do it:

var url = document.URL;
hashed_string = url.split("#");
alert(hashed_string[1]);

PHP cannot read the hash, the server doesnt even recieve it at all!