Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php library providing utf-8 file functions on windows?

I'm working on a project that does a substantial amount of pathname manipulation. It runs fine on Mac OS X but to my astonishment, there's no way to call functions like realpath with utf-8 encoded strings on Windows. This is because setlocale on Windows doesn't support utf-8:

PHP: setlocale in Windows 7

http://msdn.microsoft.com/en-us/library/x99tb11d.aspx

http://www.phpwact.org/php/i18n/utf-8

I can make wrapper functions that call utf8_encode and utf8_decode internally, but there are so many file functions in php that this places quite a burden on me.

Also the project is open source so users may perceive it as breaking when they try to use my strings (which are all utf-8 as to be web-oriented) in their own code to read/write files.

Is there a library that provides utf-8 versions of the major php file functions? I'd prefer a self-contained directory over an extension so that I can bundle it with my code.

I'm concerned that if I can't find a library like this, it may be the achilles heal that makes php unsuitable for cross platform development for me. I'm also curious how other languages like ruby, python and c++ get around this issue, if they do at all. If not, this may just be another strike against Windows and I will have to figure out another workaround.

like image 260
Zack Morris Avatar asked Nov 11 '22 19:11

Zack Morris


1 Answers

Windows setlocale() function (not php but the actual library function) does not support multi byte encodings. So you're right it is not possbile to set an utf-8 locale on windows.

You don't need to define new function however. Write a stream wrapper. Stream wrappers can be used by the most file related functions, even internal ones like loading a document in an XSLT template.

like image 186
ThW Avatar answered Nov 15 '22 04:11

ThW