开发者

get url component

My url is of the form //blogs/1824#comment-203

开发者_如何学运维

How do I get the final number 203 from the url?


You can't. The so called fragment, i.e. anything after #, is not send to the server.
It's only used client-side. You'd have to explicitly POST it to the server using Javascript.

That, BTW, is the reason Stackoverflow "double links" to individual posts:

http://stackoverflow.com/questions/4848287/get-url-component/4848295#4848295
                                                                |       |
                                                     sent to server     |
                                                                        |
                                                           not sent to server,
                                                        only used by the browser
                                                           to scroll the page


You can read it via Javascript by looking at window.location.hash.

PHP can't access it directly; the URL hash (aka fragment) component is never sent to the server.


You can do this:

$urlArray = parse_url($url);
echo $urlArray["fragment"];

Sorry but I think that the fragment is not sent to the server. You can't access it by having the URL, if you want to check more on the function, look on the documentation.

EDIT: Got a typo saying the opposite

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜