Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11327

Re: reading files with accents in the filename from PHP

Message-ID <4551425.KJ1O2EQJAU@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-10-09 22:54 +0200
Subject Re: reading files with accents in the filename from PHP
Newsgroups comp.lang.php
References <525530ed$0$15878$e4fe514c@news2.news.xs4all.nl> <l33csp$qls$1@news.albasani.net>

Show all headers | View raw


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”.

[0] <http://en.wikipedia.org/wiki/Windows-1252>
[1] <http://msdn.microsoft.com/en-us/library/windows/desktop/dd317748(v=vs.85).aspx>
[2] 
<http://en.wikipedia.org/wiki/Western_Latin_character_sets_(computing)#Comparison_table>
[3] <http://rishida.net/tools/conversion/>

BTW, you want to upgrade soon:

<http://blogs.technet.com/b/security/archive/2013/08/15/the-risk-of-running-windows-xp-after-support-ends.aspx>

> Doesn't work if stored in UTF8.

The file, or the string?

> So I suspect it's an encoding issue: the accented character "è" is stored
> as \xE8 in the file system,

Yes, it is, but only with NTFS.

> but if your script is UTF8, then your $path will contain \xC3\xA8 instead.

Which cannot work with NTFS.

> With an "explicit" $path = __DIR__ . "\Eug\xE8ne.txt" it works when the
> script is UTF8.

But only with NTFS and compatible filesystems.


PointedEars
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

reading files with accents in the filename from PHP Erwin Moller <erwinmollerusenet@xs4all.nl> - 2013-10-09 12:33 +0200
  Re: reading files with accents in the filename from PHP Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-10-09 12:58 +0200
    Re: reading files with accents in the filename from PHP Erwin Moller <erwinmollerusenet@xs4all.nl> - 2013-10-09 13:16 +0200
      Re: reading files with accents in the filename from PHP The Natural Philosopher <tnp@invalid.invalid> - 2013-10-09 12:18 +0100
        Re: reading files with accents in the filename from PHP Erwin Moller <erwinmollerusenet@xs4all.nl> - 2013-10-09 17:06 +0200
          Re: reading files with accents in the filename from PHP "Peter H. Coffin" <hellsop@ninehells.com> - 2013-10-09 10:51 -0500
          Re: reading files with accents in the filename from PHP "J.O. Aho" <user@example.net> - 2013-10-09 20:06 +0200
          Re: reading files with accents in the filename from PHP Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-10 03:07 +0200
    Re: reading files with accents in the filename from PHP Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-09 22:54 +0200
      Re: reading files with accents in the filename from PHP Christoph Michael Becker <cmbecker69@arcor.de> - 2013-10-09 23:33 +0200
        Re: reading files with accents in the filename from PHP Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-10 00:41 +0200
          Re: reading files with accents in the filename from PHP Christoph Michael Becker <cmbecker69@arcor.de> - 2013-10-31 21:34 +0100

csiph-web