Jump to content

help getting parameters correctly from url


blic

Recommended Posts

Hi all,

 

I need to get a parameter from an url, but the GET variables are passed through urldecode().

Some of my variables may have characters such as "+", ":", spaces, etc.

When I use GET, all "+" are converted to spaces. I can use urlencode to get the "+" back, but also everything that was previously a space also turns into "+".

Example:

variable = abc+ c+:D

 

Then I can get either:

abc c :D

or

abc++c+:D

 

but I want to get abc+ c+:D

 

 

Would anybody know how to help me?

 

Thanks!

Link to comment
Share on other sites

Or alternately can use

http://us.php.net/rawurldecode

and

http://php.net/manual/en/function.rawurlencode.php

 

example:

<?php
$url = "http://somesite.com/My File/script.php?value=1+2+3+4";
$decode = rawurldecode($url);
$encode = rawurlencode($decode);

echo $url."<br />";
echo $decode."<br />";
echo $encode."<br />";
?>

Link to comment
Share on other sites

thanks for the reply..

I know it works when there's only +

But when there's + and spaces is when it get's confused..

Try the same example but instead of value=1+2+3+4

try value=1+2 +3+4

the space after "2" is the one I can't get..

Link to comment
Share on other sites

try

<?php
$a='sasa + sasa';
echo '<a href="?data='. urlencode($a).'">click me</a>'."<br />\n";
if (isset ($_GET)) echo $_GET['data'];
?>

script just generate link with + and space, and echo result

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.