cURL requesting URL with whitespaces in URL.. What

2019-04-18 07:10发布

So I'm trying to curl this URL:

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

URL Encoded it reads as:

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

However, curl needs it to be decoded into a proper URL obviously.

How do i get around this problem? cURL drops off the rest of the string as soon as it reaches any whitespace... :(

I should mention I can't wrap the URL with double quotes as it is a variable being posted.

Edit: hahahahaha wowwwwww brainfart.. thanks guys :P

4条回答
女痞
2楼-- · 2019-04-18 07:32

Just use str_replace.

echo str_replace ( ' ', '%20', 'http://images.fastcompany.com/upload/Screen shot 2011-04-28 at 8.13.21 PM.png' );
查看更多
趁早两清
3楼-- · 2019-04-18 07:37

Use the str_replace(); function. Replace your " " with "%20"

查看更多
Bombasti
4楼-- · 2019-04-18 07:42

I use:

$link = trim($link);
$link = str_replace ( ' ', '%20', $link);
查看更多
混吃等死
5楼-- · 2019-04-18 07:50

Perhaps try replacing spaces with %20?

查看更多
登录 后发表回答