How to encode URL using php like browsers do

前端 未结 1 1850
遇见更好的自我
遇见更好的自我 2020-12-09 20:48

I have an URL like this

http://www.example.com/Data/image/office-dôn-sì-à.jpg

I want to copy that file to my server using copy

1条回答
  •  醉梦人生
    2020-12-09 21:26

    So, the other answers here have largely ignored your post, it seems. Let's hope I have not done the same.

    It seems to me that you only want to encode the basename? If that is true, this ad-hoc function should do the trick:

    function encode_basename($url) {
        $url = explode('/', $url);
        $base = array_pop($url);
    
        return implode('/', $url) . '/' . urlencode($base);
    }
    //returns: http://www.example.com/Data/image/office-d%25C3%25B4n-s%25C3%25AC-%25C3%25A0.jpg
    

    0 讨论(0)
提交回复
热议问题