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


Groups > comp.lang.php > #11321

Re: reading files with accents in the filename from PHP

From The Natural Philosopher <tnp@invalid.invalid>
Newsgroups comp.lang.php
Subject Re: reading files with accents in the filename from PHP
Date 2013-10-09 12:18 +0100
Organization albasani.net
Message-ID <l33e2m$sl2$1@news.albasani.net> (permalink)
References <525530ed$0$15878$e4fe514c@news2.news.xs4all.nl> <l33csp$qls$1@news.albasani.net> <52553b1f$0$15891$e4fe514c@news2.news.xs4all.nl>

Show all headers | View raw


On 09/10/13 12:16, Erwin Moller wrote:
> On 10/9/2013 12:58 PM, 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 ) );
>>
>
> That didn't help since my files are not stored in working dir.
>
>> Works on my Windows XP, PHP 5.4.8, *if* the PHP file is stored in ANSI
>> (="Windows") encoding. Doesn't work if stored in UTF8.
>
> Strange situation.
> I changed my PHP-files encoding to UTF-8, but the problem still occurred.
>
>
>   So I suspect it's
>> an encoding issue: the accented character "è" is stored as \xE8 in the
>> file system, but if your script is UTF8, then your $path will contain
>> \xC3\xA8 instead. With an "explicit" $path = __DIR__ . "\Eug\xE8ne.txt"
>> it works when the script is UTF8.
>>
>
> THAT helped!
>
> I added a replace:
> $path = str_replace("è","\xE8",$path);
>
> and now it IS readable from PHP.
>
> Now I wonder if I should make a whole list of such replaces....
> Sounds horrid, doesn't it?
>
> But your idea brought me to the following idea:
> $path = utf8_decode($path);
>
> Which works flawlessly (on my set of only 13000 filenames)!
>
> So at least I have it fixed for NTFS.
> Thanks for pointing my head in the right direction.
>
> Regards,
> Erwin Moller
>
>

and thanks for raising and solving that one..

tucked away in case its ever needed..

>> Greetings,
>> Thomas
>>
>
>


-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to 
lead are elected by the least capable of producing, and where the 
members of society least likely to sustain themselves or succeed, are 
rewarded with goods and services paid for by the confiscated wealth of a 
diminishing number of producers.

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