Escaping ampersand in URL

2018-12-31 06:39发布

I am trying to send a GET message that contains strings with ampersands and can't figure how to escape the ampersand in the URL.

Example:

http://www.example.com?candy_name=M&M
result => candy_name = M

I also tried:

http://www.example.com?candy_name=M\&M
result => candy_name = M\\

I am using URLs manually, so I just need the correct characters.

I can't use any libraries. How can it be done?

标签: http url web get
7条回答
栀子花@的思念
2楼-- · 2018-12-31 07:19

This may help if someone want it in PHP

$variable ="candy_name=M&M";
$variable = str_replace("&", "%26", $variable);
查看更多
登录 后发表回答