How to catch an hastag on the link?

Asked

Viewed 26 times

0

The following link below has a "hastag".

Example: https://site.com.br/noticia/temer-is-dead#1

I’d like to pay that #1 that is in the url.

This is possible with PHP or Js?

1 answer

0


Yes, it is possible.

With the PHP just use the function parse_url

$url = parse_url("https://site.com.br/noticia/temer-is-dead#1");
echo $url["fragment"];

To capture the current URL, complete with JS

console.log(window.location.hash.substr(1));
  • but in this case, the URL is in the address bar. Your answer is valid, I’ll see if I can do something. Thank you!

  • @I edited the answer. I added the code to get the current URL fragment with JS. The fragment is not sent to the server, so there is no way to use PHP.

  • worked out, thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.