44

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

1

6 Answers 6

47

Just use str_replace.

echo str_replace ( ' ', '%20', 'http://images.fastcompany.com/upload/Screen shot 2011-04-28 at 8.13.21 PM.png' );
Sign up to request clarification or add additional context in comments.

Comments

28

Perhaps try replacing spaces with %20?

Comments

11

I use:

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

Comments

2

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

Comments

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"

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.