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 #183113 is a reply to message #183110] Wed, 09 October 2013 18:06 Go to previous messageGo to previous message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma:
Senior Member
On 09/10/13 17:06, Erwin Moller wrote:
>> 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?
>>>> 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);

easier to use iconv and conver the string to the file systems character
setup. http://www.php.net/manual/en/function.iconv.php

But to not have to do work arounds, use the same charset as the file
system when you write your scripts, a mixed charsetup usually will cause
issues when forgetting to convert.


>>> 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?
> I don't have a good feeling about my "fix".
> It worked, but I don't know exactly what is going on.
>
> I actually hoped PHP would handle such things 'the right way', whatever
> that might be. ;-)

No there is no magic in PHP that would it change what you have hardcoded
in the script to something else just for you using a file system which
don't use the same character setup as you wrote the script in.

> Now I wonder what happens if my code happens to run on some *nix OS.
> Ideally my PHP code is OS agnostic.

Depends on which charset is used for the file system, if they use utf-8,
then no issue, of they use big5 or something else, then you have an
issue again.
You will most likely end up with issus with the file paths as other
operating systems uses / instead of \ (which is used as an escape
character).

--

//Aho
[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 Nov 28 14:37:35 GMT 2024

Total time taken to generate the page: 0.04527 seconds