Jump to content

parse ambersand in url


glenelkins

Recommended Posts

is there a way to do this? like a url like /category/Computer & Electronics/

 

If i parse this the variable only shows Computer (which makes sense!) , I tried replacing & with + and then back again but when I send Computer+Electronics the + is stripped as a white space...

Link to comment
https://forums.phpfreaks.com/topic/206507-parse-ambersand-in-url/
Share on other sites

even with urlencode() the url for example Computer & Electronics is coming back as just "Computer" when taken from $_GET

 

Must be something else in your code.  With this:

 

echo '<a href="?test=' . urlencode('Computer & Electronics') . '">Click</a>';
echo $_GET['test'];

 

I get this as the URL:  /test.php?test=Computer+%26+Electronics and this from the echo:  Computer & Electronics

 

I think its something to do with the htaccess.

 

If i access the url: index.php?route=advertiser/category/computer+%26+electronics  .... then echo $_GET['route'] shows advertiser/category/computer+%26+electronics

 

If I use the rewrite urls like: /computer+%26%+electronics  ... then echo $_GET['route'] shows advertiser/category/computer

 

this is the rewrite:

 

RewriteRule ^(.*)/$ index.php?route=advertiser/category/$1/ [L]

quote: "Apache's mod_rewrite and mod_proxy are unable to handle urlencoded URLs properly - http://issues.apache.org/bugzilla/show_bug.cgi?id=34602"

 

The most simple solution is to use urlencode twice!

 

echo urlencode(urlencode($var));

 

Apache's mod_rewrite will handle it like a normal string using urlencode once.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.