Is the fragment part of the URL handled by the browser anyway? It strikes me that it's the browser that does the work so it makes sense if the fragment isn't sent to/back from the server anyway. And if the fragment never reaches the server there is no way PHP could do anything with it.
You want the browser to jump to a section of the page determined by the URL that came as a request FROM that browser. The more I think about it, the more it seems that this would be all client side anyway.
Perhaps JavaScript would be the best way to do it.
There is something nagging at the back of my mind though.
Where do these requests originate?
If the user requests a URL then they must have either:
a) clicked a link containing the anchor
b) made up the anchor themselves
If we assume it's option a. Then that link was generated somehow, so why not store the anchor as a parameter and pass it along in the URL.
Then on the recieving page create the anchors dynamically based on the parameter.
If your sections are being generated dynamically from a database you could add an anchor at the top of each section that matches, for example, the record ID.
Then any link generated that points to that section gets the ID appended as an anchor.
Example.
We have a product, an Umbrella, in a database with an ID of '1345'.
We have a page with a link to that product, we create the link with PHP something like this,
Code:
<a href="products.php#<?=$id;?>?anchor=<?=$id;?>Umbrella</a>
Then on the page that has the Umbrella
Code:
<?
echo ("<a name=".$anchor."></a>");
echo ("<h1>Umbrella</h1>");
echo ("<p>Keeps you dry</p>");
?>
There's probably a gaping hole in that idea... I just made it up as I was typing :)
Hopefully it will kick off some lateral thinking though.