Reputation: 15
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']));
Upvotes: 0
Views: 341
Reputation: 15
I corrected this by converting #
to %23
before urlencoding the url using the code below,
str_replace("#","%23",$_REQUEST['search_keyword']);
Upvotes: 0
Reputation: 4144
You cannot retrieve nothing after the #, any browser will remove because this is a anchor.
This is explained at: Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
You you want get this # you must slugify/urlize your url with some library like Slugify this will encode the "strange" chars.
Example:
use Cocur\Slugify\Slugify;
$slugify = new Slugify();//for iconv translit
echo $slugify->slugify('Hello World!'); // hello-world
I think that this is better than let to the browser make a simple url encode.
Upvotes: 2