-3

My website URL is something like the below:

http://localhost/naveendalmeida/news.php#news_6

How can I get the URL to include #news_6 using PHP or JavaScript.

Ben
  • 51,770
  • 36
  • 127
  • 149
Naveen D Almeida
  • 877
  • 6
  • 16
  • 4
    https://www.google.com/search?q=get+url+hash+php+javascript – Your Common Sense Feb 23 '13 at 18:27
  • 2
    @YourCommonSense To be fair, none of those results (that I saw) directly answer the question. – Wesley Murch Feb 23 '13 at 18:40
  • 1
    And who is voting to close "not a real question"? To me the question is crystal clear, just *very* basic. This could be the top Google result within a couple weeks and then you can close others as "duplicate". – Wesley Murch Feb 23 '13 at 18:42
  • possible duplicate of [Get current URL with javascript?](http://stackoverflow.com/questions/1034621/get-current-url-with-javascript) ;) – Wesley Murch Feb 23 '13 at 18:45

3 Answers3

3

window.location.href should return what you need (javascript).

Getting it in php seems a little more verbose:-

http://www.phpf1.com/tutorial/get-current-page-url.html

Mat Richardson
  • 3,576
  • 4
  • 31
  • 56
0

Using JavaScript

if(window.location.hash) {
  alert(window.location.hash);
} 
Winston
  • 1,758
  • 2
  • 17
  • 29
-3

For php parse_url function is utilized for parsing url

For retrieving fragment part of url through parse_url function

e.g

$url_info=parse_url($url);

echo $url_info['fragment'];

Rubin Porwal
  • 3,736
  • 1
  • 23
  • 26