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
How to encode spaces in curl request URL? You can use the --date-urlencode option of curl : --data-urlencode <data> (HTTP) This posts data, similar to the other --data options with the exception that this performs URL-encoding. (Added in 7.18.
To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option.
curl is called curl because a substring in its name is URL (Uniform Resource Locator). It operates on URLs. URL is the name we casually use for the web address strings, like the ones we usually see prefixed with HTTP:// or starting with www.
URL encoding. Percent-encoding, also known as URL encoding, is technically a mechanism for encoding data so that it can appear in URLs. This encoding is typically used when sending POSTs with the application/x-www-form-urlencoded content type, such as the ones curl sends with --data and --data-binary etc.
Just use str_replace.
echo str_replace ( ' ', '%20', 'http://images.fastcompany.com/upload/Screen shot 2011-04-28 at 8.13.21 PM.png' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With