Why does the following code mistakenly renames 1.txt
to 一.txt.txt
and not 一.txt
?
rename('1.txt','一.txt');
Mostly because of encoding mismatch. You script shall use right encoding and this encoding have to match file system encoding. If one of these mismatch (usually script's) then you get the described effect. Ensure you use the same encoding or replace your "in-lined" name (FYI your target file name looks here as "-.txt" where "-" is long dash) with numeric entity.
Ah the joy of mixed encoding. The mistake could be anywhere, in your file system, in your network encoding, in your shell, in your editor, in your file manager, even in the terminal not interpreting the characters correctly, ...
Please ensure that everybody speaks the same character set. This is usually fixed by running with the correct environment variables in place. Please be aware of the fact the PHP doesn't really do anything with the file name's characters, so as long as you're not using string functions to manipulate strings (which are, unfortunately, still only compatible with single byte strings) you shouldn't be in much trouble from PHP.