Urlencode and file_get_contents

后端 未结 2 735
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 04:00

We have an url like http://site.s3.amazonaws.com/images/some image @name.jpg inside $string

What I\'m trying to do (yes, there is a whitesp

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 04:25

    Using function urlencode() for entire URL, will generate an invalid URL. Leaving the URL as it is also is not correct, because in contrast to the browsers, the file_get_contents() function don't perform URL normalization. In your example, you need to replace spaces with %20:

    $string = str_replace(' ', '%20', $string);
    

提交回复
热议问题