I need to URL encode just the directory path and file name of a URL using PHP.
So I want to encode something like http://example.com/file name and have it r
http://example.com/file name
function encode_uri($url){ $exp = "{[^0-9a-z_.!~*'();,/?:@&=+$#%\[\]-]}i"; return preg_replace_callback($exp, function($m){ return sprintf('%%%02X',ord($m[0])); }, $url); }