-1

I'm passing simple query string:

index.php?a=orange&apple

Getting value with:

$_GET['a'];

it only shows orange value. i have tried

$a = urlencode($_GET['a']);
$rs = urldecode($a);
echo $rs; // orange;

but didn't work. Found similar question here stackoverflow but seems not useful. How do i get complete value orange&apple?

James Z
  • 12,209
  • 10
  • 24
  • 44
RanaHaroon
  • 445
  • 6
  • 20

3 Answers3

4

That is because & makes apple as another value in GET request.

Like this -

/test/demo_form.php?name1=value1&name2=value2

So use '%26'(encoding URI Component) in place of & like this -

index.php?a=orange%26apple

And get the value with $_GET['a'];. This should work.

pro_cheats
  • 1,534
  • 1
  • 15
  • 25
1

Your query string need to encode ampersand(&) as percent-encode as %26. Your url will be like :

index.php?a=orange%26apple
Gyan
  • 498
  • 6
  • 10
0

Write it like this:

index.php?a=orange&b=apple

// Values

$_GET['a'];
$_GET['b'];
Evhz
  • 8,852
  • 9
  • 51
  • 69