|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-06-14 17:13 UTC] victorepand at gmail dot com
Description: ------------ cURL does not work when the URL has a ’ character in it. Such as, for example, this one: http://www.motorcycle-superstore.com/ProductImages/60/2009_GMax_Women’s_GM17_Derk_Open-Face_Helmet.jpg Reproduce code: --------------- $ch=curl_init(); $url="http://www.motorcycle-superstore.com/ProductImages/60/2009_GMax_Women’s_GM17_Derk_Open-Face_Helmet.jpg" curl_setopt($ch,CURLOPT_URL,$url); $result=curl_exec ($ch); Expected result: ---------------- thumbnail image in binary stored in result Actual result: -------------- curl error PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 18:00:01 2025 UTC |
The error returned by cURL is: 22 The requested URL returned error: 404 I created this function which solves the problem: function urlencode_url($url) { if (!($ei=strpos($url,"?"))) $ei=strlen($url); $newurl=str_replace(array("%3A","%2F"),array(":","/"),urlencode(urldecode(substr($url,0,$ei)))).substr($url,$ei); return $newurl; } By passing the URL through this function, the offending character is converted to its urlencoded equivalent (%##). With these codes instead of the bad character, cURL reads the URL with no problem. Nonetheless, I reported this issue because Internet Explorer does not require the urlencoded codes. It loads the original URL with no problem, using the original bad character in the URL. Therefore, the cURL behavior is more strict in its requirement of the URL being urlencoded than Internet Explorer is. Perhaps cURL could automatically urlencode the URL, or perhaps a function should be made for this purpose like the one I have shown above.