I think this will work for you:
function file_url($url){ $parts = parse_url($url); $path_parts = array_map('rawurldecode', explode('/', $parts['path'])); return $parts['scheme'] . '://' . $parts['host'] . implode('/', array_map('rawurlencode', $path_parts)) ; } echo file_url("http://example.com/foo/bar bof/some file.jpg") . "\n"; echo file_url("http://example.com/foo/bar+bof/some+file.jpg") . "\n"; echo file_url("http://example.com/foo/bar%20bof/some%20file.jpg") . "\n";
Exit
http://example.com/foo/bar%20bof/some%20file.jpg http://example.com/foo/bar%2Bbof/some%2Bfile.jpg http://example.com/foo/bar%20bof/some%20file.jpg
Note:
I would use urldecode and urlencode for this, since the output would be identical for each url. rawurlencode save + , even if %20 is probably appropriate for any url you use.
maček
source share