cURL使用URL中的空格请求URL ..怎么做

时间:2011-05-09 02:16:54

标签: php parsing curl communication

所以我试图卷曲这个网址:

http://images.fastcompany.com/upload/Screen shot 2011-04-28 at 8.13.21 PM.png

URL编码,读作:

http%3A%2F%2Fimages.fastcompany.com%2Fupload%2FScreen+shot+2011-04-28+at+8.13.21+PM.png

然而,curl显然需要将其解码为正确的URL。

我如何解决这个问题?一旦到达任何空格,cURL就会掉掉字符串的其余部分...... :(

我应该提到我不能用双引号包装URL,因为它是一个被发布的变量。

编辑:hahahahaha wowwwwww brainfart ..谢谢你们:P

5 个答案:

答案 0 :(得分:23)

只需使用str_replace。

echo str_replace ( ' ', '%20', 'http://images.fastcompany.com/upload/Screen shot 2011-04-28 at 8.13.21 PM.png' );

答案 1 :(得分:11)

也许尝试用%20替换空格?

答案 2 :(得分:2)

我用:

$link = trim($link);
$link = str_replace ( ' ', '%20', $link);

答案 3 :(得分:0)

使用str_replace();功能。将" "替换为"%20"

答案 4 :(得分:0)

对我来说,只需在名称之间加一个空格即可。

示例

curl --upload-file "001- name - lastName.pdf" https://transfer.sh/ernesto

请注意在“ 001-名称-lastName.pdf”中使用“”

相关问题