PHP评论字符转义

I made .htaccess file that redirects for example link:

website.com/module#controller

to:

website.com/?url=module#controller

As # is PHP comment declarer, I get problem when need to load:

$bootstrap->init($url) // $url = module#controller;

I tried to use addslashees($url); , but still when I:

echo $url;

I still get output of:

module

How I should clear that string, to threat # sign as part of string?

$url = module#controller; is not valid PHP.

$url = 'module#controller'; will (correctly) not treat the # as a comment initiator.

Additionally, a # in a URL isn't going to work the way you expect. That's the marker for the URL hash/anchor, which is not passed to the web server. This is likely why you get output of module - your problem is at the browser level, not PHP.

The hashtag fragment identifier is a client-side concept only. The browser would never send a hashtag value to the server.

If you are relying on this functionality, your are going to be disappointed as server has absolutely no way to do redirection based on the hashtag, as it never even sees the hashtag.