Saravanan Sampathkumar
Saravanan Sampathkumar

Reputation: 3261

PHP error using & in url

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.

Upvotes: 0

Views: 60

Answers (2)

Ja͢ck
Ja͢ck

Reputation: 173562

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')
);

Upvotes: 0

Raptor
Raptor

Reputation: 54212

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

sidenote: Difference of the 2 functions

Upvotes: 2

Related Questions