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
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

 

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.