Search code examples
phpquery-stringquerystringparameter

Pass # as text in querystring in php


I have this url https://www.industrialstores.com/search_results/Asco+8214G30+3%252F4%5C%5C%5C%220%252F5%23+Gas+Shutoff+Valve/46

but in above, %23 is # before Gas in url and making all the things after this unreadable in php.

When I trying to fetch the value of s & o from the query string, I am not getting any value for o and for s, only Asco+8214G30+3%252F4%5C%5C%5C%220%252F5 returns but it should return Asco+8214G30+3%252F4%5C%5C%5C%220%252F5%23+Gas+Shutoff+Valve

I am using httaccess rewrite to make this url RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([^/]+)?$ index.php?page=$1&s=$2&o=$3 [L]

And code for fetching the querystring value as :

if(isset($_GET['s'])){

$search_keyword=str_replace("_"," ",$_GET['s']);
}
if(isset($_GET['o']) && $_GET['o'] !=''){
$searchin = $_GET['o'];
}

And setting query string values as below:

$keyword = urlencode(str_replace("/","%2F",$_REQUEST['search_keyword']));

Solution

  • I corrected this by converting # to %23 before urlencoding the url using the code below,

    str_replace("#","%23",$_REQUEST['search_keyword']);