diff options
author | andi <andi@splitbrain.org> | 2005-01-23 19:27:53 +0100 |
---|---|---|
committer | andi <andi@splitbrain.org> | 2005-01-23 19:27:53 +0100 |
commit | f59b22f06ff9991411582125e93ead71a4da0a3c (patch) | |
tree | 5297b3a25154e91029b4de9a1e4a5ae4f8ef5fec /inc/utf8.php | |
parent | d5a2a500a561c1264c42fd7113cbd20426ed8dad (diff) | |
download | rpg-f59b22f06ff9991411582125e93ead71a4da0a3c.tar.gz rpg-f59b22f06ff9991411582125e93ead71a4da0a3c.tar.bz2 |
safe mode for utf8_encodeFN
darcs-hash:20050123182753-9977f-9226687e01f083dbeea7a205db30a6d74ed2eb5f.gz
Diffstat (limited to 'inc/utf8.php')
-rw-r--r-- | inc/utf8.php | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/inc/utf8.php b/inc/utf8.php index 3e5f5decd..80b85637b 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -11,10 +11,19 @@ * * Slashes are not encoded * + * When the second parameter is true the string will + * be encoded only if non ASCII characters are detected - + * This makes it safe to run it multiple times on the + * same string (default is true) + * * @author Andreas Gohr <andi@splitbrain.org> + * @see urlencode */ -function utf8_encodeFN($file){ - $file = rawurlencode($file); +function utf8_encodeFN($file,$safe=true){ + if($safe && preg_match('#^[a-zA-Z0-9/_\-.%]+$#',$file)){ + return $file; + } + $file = urlencode($file); $file = str_replace('%2F','/',$file); return $file; } @@ -22,10 +31,13 @@ function utf8_encodeFN($file){ /** * URL-Decode a filename * + * This is just a wrapper around urldecode + * * @author Andreas Gohr <andi@splitbrain.org> + * @see urldecode */ function utf8_decodeFN($file){ - $file = rawurldecode($file); + $file = urldecode($file); return $file; } @@ -52,7 +64,6 @@ function utf8_check($Str) { return true; } - /** * This is a unicode aware replacement for strlen() * |