FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » reading files with accents in the filename from PHP
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: reading files with accents in the filename from PHP [message #183119 is a reply to message #183116] Wed, 09 October 2013 21:33 Go to previous messageGo to previous message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma:
Senior Member
Thomas 'PointedEars' Lahn wrote:

> Thomas Mlynarczyk wrote:
>
>> Erwin Moller schrieb:
>>> How can PHP open files on the local filesystem that contain certain
>>> characters, like umlauts, accents, etc?
>>
>> $path = __DIR__ . '\Eugène.txt';
>> var_dump( PHP_VERSION, file_exists( $path ) );
>>
>> Works on my Windows XP, PHP 5.4.8, *if* the PHP file is stored in ANSI
>> (="Windows") encoding.
>
> There is no “ANSI encoding“. Usually “ANSI encoding” means Windows-1252.
> [0] It would be either coincidence or strange if this worked, because FAT32
> uses the “OEM character set”, i. e. one of the various IBM code pages, 437
> for English, and NTFS uses UTF-16BE [1]. The letter “è” has Windows-1252
> code 0xE6, IBM437/IBM850 code 0x8A, and Unicode code point U+00E8 [2]
> (encoded in UTF-16 as 0xE8 [3]). It follows that you cannot mean
> Windows-1252 by “ANSI”.

The letter "è" is encoded in CP-1252 as /0xE8/[1]. In UTF-16 it is
encoded by *two* bytes: 0x00 0xE8 (or vice versa, depending on the
endianess).

I have created a file "tèst" on a German Windows XP on NTFS, and started
a PHP shell:

>>> $fs = glob('t?st')
>>> $fs[0]
't\350st'

Apparently, the file name is *read* by PHP as if it was encoded in
CP-1252. Either the description on MSDN[2] is wrong, or PHP uses a
Windows API that converts the filename's encoding. I presume the
latter, being aware (but not (yet) convinced) that there might be
another reason for this behavior.

[1] <http://en.wikipedia.org/wiki/Windows-1252>
[2]
<http://msdn.microsoft.com/en-us/library/windows/desktop/dd317748(v=vs.85).aspx>

> BTW, you want to upgrade soon:

Me too. :)

--
Christoph M. Becker
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PDO - Cannot retrieve warnings with emulated prepares disabled
Next Topic: Secure website
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Sep 19 02:09:46 GMT 2024

Total time taken to generate the page: 0.05163 seconds