0

There is a string XX&YY and I'm passing it to another page. ie, localhost/sample/XX&YY/1 for some processing. Now when I try getting the name value on the other side I'm able to get only XX and not full XX&YY. How to rectify it? Any ideas?

Note : here is my url localhost/sample.php?name=somevalue&pageno=somevalue has been url re-written to localhost/sample/name/pageno.

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
Saravanan Sampathkumar
  • 3,201
  • 1
  • 20
  • 46
  • are you using URL rewritting? anyway you should encode the & as it's used to determine whenever you have a new parameter – aleation Apr 12 '13 at 07:44

2 Answers2

2

You have to escape the URL . You can use rawurlencode() or urlencode() to encode your URL.

sidenote: Difference of the 2 functions

Community
  • 1
  • 1
Raptor
  • 53,206
  • 45
  • 230
  • 366
0

If I'm understanding correctly, this is the URL to your script:

http://localhost/sample/name/pageno

Which is then rewritten by your web server to this:

http://localhost/sample.php?name=somevalue&pageno=somevalue

Then, this is how you should format the URL:

$url = sprintf('http://localhost/sample/%s/%s', 
    urlencode('XX&YY'), 
    urlencode('1')
);
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309