开发者

To Retrieve string followed by # in a url

I have a URL of the form:- http://开发者_如何学Cwww.sboxeppp.com:88/phones.php?iden=true#6786

Now i want to retrieve number (6786) followed by # in server side. How can i do that?


anything behind the hash can only be accessed by client side scripts, since it won't be sent to the server you can use the parse_url() function

more here: http://php.net/manual/en/function.parse-url.php


You cannot do that. The part of the url after the hash is called a fragment, and it does not get sent to the server. It's only available to client scripting.

The only way that you could do this is by retrieving the fragment from JavaScript (using window.location.hash) and communicating this information to the server with an AJAX request specifically made for this purpose. Of course this means that the server will have to render the page first and get notified of the fragment later, which is a totally different workflow than what you want.


You can't do that, because it's a directive for browser only. You can use AJAX requests to send the required info to server.


Right, it didnt let me post that as an answer -

var hashNumber = window.location.hash should work.

hashNumber = hashNumber.substring(1)

See:

How can you check for a #hash in a URL using JavaScript?


Use parse_url:

parse_url('http://www.sboxeppp.com:88/phones.php?iden=true#6786',
          PHP_URL_FRAGMENT);

Notice that the fragment doesn't get sent to the server if it's in the form's target property. Instead, just write the information in the fragment in a hidden element, like this:

<input type="hidden" name="_fragment" value="6786" />

And read the fragment from $_POST['_fragment'].

If the fragment is generated client-side (or somehow determined by the user), you'll have to create that element on the client. You can access the current fragment in JavaScript with window.location.hash.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜