I am trying to post # parameter in query string like...
www.demo.php?tag=c#
Now i am trying to get tag value in another page with
$_GET['tag']
But i am not getting somehow # value is not coming with $_GET. I can get only "c".
I am trying to post # parameter in query string like...
www.demo.php?tag=c#
Now i am trying to get tag value in another page with
$_GET['tag']
But i am not getting somehow # value is not coming with $_GET. I can get only "c".
The hash character (#
) has a special meaning in URLs. It introduces a fragment identifier. A fragment identifier is usually used to locate a certain position inside the page.
A fragment identifier is handled by the browser, it is removed from the URL when the browser makes the HTTP request to the server.
Being a special character, if you want it to have its literal value you must encode it. The correct way to write the URL in your question is:
www.demo.php?tag=c%23
When it's written this way, $_GET['tag']
contains the correct value ('c#'
).
If you generate such URLs from PHP code (probably by getting the values of tag
from an external resource like a database) you have to use the PHP function urlencode()
to properly encode the values you put in URLs. Or, even better, create an array with all the URL arguments and their values then pass it to http_build_query()
to generate the URL:
$params = array(
'tag' => 'c#',
'page' => 2,
);
$url = 'http://localhost/demo.php?'.http_build_query($params);