38

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

Atticus
  • 6,585
  • 10
  • 35
  • 57
  • this is another alternative to doing exactly that: http://unix.stackexchange.com/questions/86729/any-way-to-encode-the-url-in-curl-command – David T. Dec 05 '14 at 04:18

6 Answers6

44

Just use str_replace.

echo str_replace ( ' ', '%20', 'http://images.fastcompany.com/upload/Screen shot 2011-04-28 at 8.13.21 PM.png' );
Kane Wallmann
  • 2,292
  • 15
  • 10
26

Perhaps try replacing spaces with %20?

Drew
  • 2,269
  • 21
  • 16
8

I use:

$link = trim($link);
$link = str_replace ( ' ', '%20', $link);
Hoàng Vũ Tgtt
  • 1,863
  • 24
  • 8
2

For me just to put the name with spaces between "" worked.

Example

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

Notice the use of "" in "001- name - lastName.pdf"

Juanma Menendez
  • 17,253
  • 7
  • 59
  • 56
1

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

Kees C. Bakker
  • 32,294
  • 27
  • 115
  • 203
Mitchell M
  • 475
  • 1
  • 7
  • 15
0

On Windows, you can use notepad++

  1. Write the text in the file and open it in notepad++.
  2. Select an empty string in the text and then click on search.
  3. Search box will appear, Now click on replace tab.
  4. Select the Extended check box in the Search Mode option.
  5. Click replace enter image description here
Amit Meena
  • 2,884
  • 2
  • 21
  • 33