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 #183109 is a reply to message #183108] Wed, 09 October 2013 11:18 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
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.
[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: Sun Nov 24 21:52:20 GMT 2024

Total time taken to generate the page: 0.06392 seconds