urlencode() 不起作用

3

I have a URL like this:

http://x.x.x.x/feedsms?to=$groupName&text=$content"

当我调用这个URL时,它应该发送一条短信。我使用file_get_contents()读取短信内容,并使用urlencode()处理空格和特殊字符。
$url = urlencode("http://x.x.x.x/feedsms?to=$groupName&text=$content");
$urlContent = file_get_contents($url);

$content是这样的:

F: user@domain.com S: Veeam Repoting B: Target: y.y.y.y, Status: Error, Time: 8/22/2015 3:05:30 PM

但我无法调用该URL:

file_get_contents(): failed to open stream: No such file or directory ... 

我尝试使用rawurlencode()进行转码,但没有任何改变。

1个回答

4

urlencode 应该被用来将字符串编码成可以在 URL 查询部分中使用的格式。你不应该对整个 URL 使用它,而只应该对需要被编码的每个参数使用它,比如你的 $groupName$content。像这样做应该就可以了:

$url = "http://x.x.x.x/feedsms?to=" . urlencode($groupName) . "&text=" . urlencode($content);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接