It is physically impossible to get the
#anchor part via PHP, since PHP never has access to that information. This SO thread describes the issue.
If you're trying to access the
#anchor in Twig, you're probably out of luck there too. Twig is just a PHP parser, so you've essentially got the same problem.