Walrus
Walrus

Reputation: 20444

PHP echo the hash url

I am trying to echo the hash at the end of the URL.

This didn't work

<?php 

echo '<script type="text/javascript">
$(this).hash.substring(1);</script>';?>

Any ideas?

Upvotes: 0

Views: 708

Answers (2)

Dave Child
Dave Child

Reputation: 7881

It looks like you're trying to combine two languages, but I don't think it's possible to do what you want this way. At a guess, you're trying to get the "#hashbit" from a url like this:

http://www.example.com/page.php?something#hashbit

Unfortunately, the browser doesn't send the "#hashbit" to the server. It's only used on the client side. You could write some JavaScript to grab the "#hashbit" to the server separately.

Upvotes: 0

Gumbo
Gumbo

Reputation: 655269

Try location.hash.substring(1) instead:

echo '<script type="text/javascript">
var fragment = location.hash.substring(1);</script>';

Note that this PHP code does only echo HTML and JavaScript code to get that fragment value. PHP itself cannot retrieve that part of the URI as it is not part of the requested URI but only locally available.

Upvotes: 1

Related Questions