tags:

views:

39

answers:

3

I am using rename() to move a file from one folder to another with php.

It works fine with folders which don't have the swedish å ä ö characters involved.

Is there any way around this? (except for changing the folder names to something without special chars)

The website is entirely in utf-8 format...

A: 

Use the unicode normalize functions to normalize the filepath?

filePath = unicodedata.normalize('NFD', filePath);
TheGrandWazoo
He doesn't want to change the folder names. It's great to know about the normalizer though, thanks for the link!
Pekka
A: 

Hi, this seems to be a bug which i am not sure whether it has been solved or not. You can use the regular expression to clean file/folder names though. Or as pointed out by TheGrandWazoo you can use the normalizer class.

Sarfraz
+2  A: 

This seems to be a bit of a grey area looking at the the manual chapter on rename() and the User Contributed Notes. There is no word on what encoding should be used. Anyway, if the filesystem supports it, it should be possible to use UTF-8 in file names.

This SO question has a very clever answer to work around this. It's not 100% pure-bred, but probably workable in most cases.

If the characters you are using are also available in iso-8859-1, you could also try a simple utf8_decode(). But that solution is not complete and not perfect, as it will fail on characters outside the map.

Pekka
(+1) Great comment. Didn't realise there was another work around :)
TheGrandWazoo