如何在URL中传递特殊字符 [英] How to pass special characters in a URL
本文介绍了如何在URL中传递特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向API发送经典的GET请求: http://mywebsite.com ?arg1 = val1& arg2 = val2 。
问题是如果 val1 或 val2 包含&,我不知道该怎么办要么 ?字符。我知道 urlencode()函数,但是我不确定在这种情况下它是否会有所帮助,因为&之间必须有所区别用于分隔参数和&
I am trying to send a classic GET request to an API : http://mywebsite.com?arg1=val1&arg2=val2. The problem is I don't know what to do if val1 or val2 contains a "&" or "?" character. I know the urlencode() function but I'm not sure it would help in this case as there needs to be a difference between the "&" used to separate the arguments and the "&" contained by the arguments.
有人可以帮忙吗?
谢谢
Can anyone help? Thanks
推荐答案
我终于找到了一个简单得多的解决方案。 urlencode()达到了目的:
I finally found a much simpler solution. urlencode() did the trick:
$url = 'http://mywebsite.com?arg1='.urlencode('val1').'arg2='.urlencode('val2').......
谢谢大家的答复。
这篇关于如何在URL中传递特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文