如何使用php的exec将空格放入curl的URL中

时间:2013-10-29 23:01:17

标签: php unix curl exec

我正在使用exec做一个卷曲。问题是这两个:

exec("curl --insecure https://site.com/?term=last day&x=1");

exec("curl --insecure https://site.com/?term=last%20day&x=1");

给我一​​个错误,因为“term”参数中没有合适的字符串。如果我只是去https://site.com/?term=last日& x = 1,它可以正常工作,但显然%20不会在其结尾处转换为空格。

我认为在curl中将空格放入URL是个问题。最简单的方法是什么?

1 个答案:

答案 0 :(得分:0)

您需要使用escapeshellarg()

exec('curl --insecure ' . escapeshellarg($url));

exec()在内部启动一个shell,如果你没有正确地转义字符,那么shell可能会在字符串中展开元字符,如&