1

It works

$url = parse_url('http://yabadaba.com/brand#asos');
echo $url['fragment'];

But it doesn't work

$url = parse_url($_SERVER['REQUEST_URI']);
echo $url['fragment'];

What is wrong? :(

wp student
  • 755
  • 9
  • 24

1 Answers1

1

That is because the parameter preceded by # will not reach the server-side script. You can get it only by Javascript.

Why does it work on the first case ?

  • That is because you are hard-coding it in the parse_url function.
Community
  • 1
  • 1
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • I can do it with query string but hashtag looks modern. So according to you, I'll need to pass javascript to php. Which will not work if javascript is disabled. – wp student Mar 17 '14 at 10:04
  • 1
    @Waqas The modern part of hashtag goes together with dynamically loading the content via Ajax ... you can't really do one without the other :) – Ja͢ck Mar 17 '14 at 10:10
  • 1
    If you are looking to parse the variables with PHP , you need to pass the parameters in the _usual_ way you do it. Btw I don't see any _moderness_ in the `#` btw :) – Shankar Narayana Damodaran Mar 17 '14 at 10:10