php file_get_contents 编码问题
我正在尝试将短信服务集成到我的网站中。我需要使用名为“msg”(urlencoded)的参数进行 HTTP 调用。
目前,我正在使用经过 urlencode 的 msg 参数构建整个 URL(即 $msg = urlencode($msg)
),并且正在发送短信。
$msg = urlencode("Hello World");
虽然我在手机上收到的是“Hello+World”而不是“Hello World”。
那么 file_get_contents
有问题吗?
另外,无论如何,我可以看到字符串“file_get_contents”最终发送出去吗?
I am trying to Integrate an SMS service into my website. I need to make a HTTP call with a param named "msg" (urlencoded).
Currently, I am constructing the entire URL with msg param being urlencoded (i.e $msg = urlencode($msg)
), and I am sending the SMS.
$msg = urlencode("Hello World");
Although what I receive on my phone is "Hello+World" and NOT "Hello World".
So is there an issue with file_get_contents
?
Also, is there anyway, I can see the string "file_get_contents" finally sends out ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用
rawurlencode()
代替。主要区别(尽管还有其他区别)是它将空格编码为
%20
而不是+
。这很可能是您问题的根源。Try using
rawurlencode()
instead.The principal difference (although there are others) is that it encodes spaces as
%20
instead of+
. This is quite likely the source of your problem.我想出了问题所在:
我使用
http_build_query
创建查询字符串,并且我向它传递了urlencode
参数。因此它被编码了两次。不。
是的,使用网络嗅探器。
I figured what was the issue:
I was using
http_build_query
to create the query string, and I was passing aurlencode
'd param to it. Hence it was being encoded twice.No.
Yes, with a network sniffer.
检索数据后需要使用 urldecode() 然后显示给用户
You need to use urldecode() after retrieving data and then display to user