Coming back to this - what I was trying to do:
I have a navigation menu with links that change background colour to indicate which page you're on - eg if you're on the contact page, the contact page link will have a gray background.
<a href="contact.php" <?php if(basename($_SERVER['PHP_SELF']) == "contact.php") {echo "style='background-color:#ccc;' "; } ?> />contact</a>
If there's another link to 'feedback form' which is half way down the contact page
<a href="contact.php#feedback" />
then I need to detect that #feedback.
That was the problem.
This is the workaround:
Make the link submit a form:
<form action="contact.php#feedback" method="POST" name="form">
<input name="feeback" type="hidden" value="feedback" />
</form>
<a href="#" onclick="document.form.submit()" >feedback form</a>
--
Instead of detecting #feedback I can now detect the $POST['feedback'] and use that to change the background colour of the link eg -
<a href="#" onclick="document.form.submit()" <?php if(isset($_POST['feedback'])){echo "style='background-color:#ccc;' "; } ?> / >feedback form</a>