0

i passing below url in address bar

www.example.com/latest_notes/?shareURL&adherentID=ascd#123 i want get the after # value of 123 this page i have tried SERVER function i can able to get UL without #, Please any one help

  • 1
    Possible duplicate of [retrieve the hash in the url with php?](http://stackoverflow.com/questions/1957030/retrieve-the-hash-in-the-url-with-php) – Shira Feb 28 '17 at 13:28

2 Answers2

1

Convert the url string to a PHP url object with the function parse_url and dereference its "fragment" key like this:

$url=parse_url("www.example.com/latest_notes/?shareURL&adherentID=ascd#123");
echo $url["fragment"]; 

The above code returns 123

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Mani7TAM
  • 469
  • 3
  • 10
-1

Take a look at the function parse_url, it does what you need. http://php.net/manual/en/function.parse-url.php

$url = 'http://username:password@hostname:9090/path?arg=value#anchor';
var_dump(parse_url($url));
var_dump(parse_url($url, PHP_URL_SCHEME));
var_dump(parse_url($url, PHP_URL_USER));
var_dump(parse_url($url, PHP_URL_PASS));
var_dump(parse_url($url, PHP_URL_HOST));
var_dump(parse_url($url, PHP_URL_PORT));
var_dump(parse_url($url, PHP_URL_PATH));
var_dump(parse_url($url, PHP_URL_QUERY));
var_dump(parse_url($url, PHP_URL_FRAGMENT));

You need the #anchor values: use the last line of code

var_dump(parse_url($url, PHP_URL_FRAGMENT));

Possible duplicate question Get fragment (value after hash '#') from a URL in php

Simone Cabrino
  • 901
  • 9
  • 24