Bluehost.com Web Hosting $6.95

File handling and different character sets

This is a discussion on File handling and different character sets within the PHP General forums, part of the PHP Programming Forums category; Hi, I would like to know how you work with the PHP Directory Functions and different character sets. If I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-23-2007
Per Eriksson
 
Posts: n/a
Default File handling and different character sets

Hi,

I would like to know how you work with the PHP Directory Functions and
different character sets. If I am having a professional view,
well-written code should be able to handle file systems in different
character sets.

http://se.php.net/manual/sv/ref.dir.php

Is there a way to write code for listing files from a ISO-8859-1 on a
UTF-8 page? I haven't succeeded with this.


Thank you,

Best Regards

Per Eriksson
per.eriksson A exist ! se
Reply With Quote
  #2 (permalink)  
Old 11-24-2007
Andrés Robinet
 
Posts: n/a
Default RE: [PHP] File handling and different character sets

> -----Original Message-----
> From: Per Eriksson [mailto:per.eriksson@exist.se]
> Sent: Friday, November 23, 2007 7:15 AM
> To: php-general@lists.php.net
> Subject: [php] File handling and different character sets
>
> Hi,
>
> I would like to know how you work with the PHP Directory Functions and
> different character sets. If I am having a professional view,
> well-written code should be able to handle file systems in different
> character sets.
>
> http://se.php.net/manual/sv/ref.dir.php
>
> Is there a way to write code for listing files from a ISO-8859-1 on a
> UTF-8 page? I haven't succeeded with this.
>
>
> Thank you,
>
> Best Regards
>
> Per Eriksson
> per.eriksson A exist ! se
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


Hi Per,

I'm just curious, no matter what encoding I choose (IE and FF switch
automatically to UTF-8 as per the page metatag and content-type header) I
get funny characters at http://se.php.net/manual/sv/ref.dir.php, I don't
know if this is because of the default browser font, because I've tried
several ones. My system is Windows XP SP2 Spanish version, but I don't think
that's the cause either as it is up to date, and I have even installed
support for right to left writing...
Ok, I know I can just use wget, save the result and open it in a binary
editor to see what are the actual bytes and check for the encoding (I
won't... I'm kind of lazy today :D )

Regarding your question, I have these functions I copied from the notes to
the extended CHM version of the PHP manual, they are at the
mb_convert_encoding function reference and should be in the online version
of the manual as well (won't check it... too lazy, I told you)...

[snip]
volker at machon dot biz (25-Sep-2007 05:05)

Hey guys. For everybody who's looking for a function that is converting an
iso-string to utf8 or an utf8-string to iso, here's your solution:
public function encodeToUtf8($string) {
return mb_convert_encoding($string, "UTF-8", mb_detect_encoding($string,
"UTF-8, ISO-8859-1, ISO-8859-15", true));
}
public function encodeToIso($string) {
return mb_convert_encoding($string, "ISO-8859-1",
mb_detect_encoding($string, "UTF-8, ISO-8859-1, ISO-8859-15", true));
}
For me these functions are working fine. Give it a try
[/snip]

The first thing to test for would be if the directory/filesystem functions
are retrieving data encoded in ISO-8859-1 or not (I guess it depends on the
OS, but you might know better), otherwise mb_convert_encoding would act like
"double escaping" or "double urlencoding" (a known issue for all of us,
ha?). That's why encodeToUtf8 uses mb_detect_encoding first... anyway, I
wonder if mb_detect_encoding can guarantee you anything other than the byte
stream of data being valid in the given character set(s). So... what do you
think, did you get any further results about this? And also, do you have any
code sample you are working on to share?

Regards,

Rob


Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308
| TEL 954-607-4207*| FAX 954-337-2695 |
Email: info@bestplace.net *| MSN Chat: best@bestplace.net *| *SKYPE:
bestplace | *Web: bestplace.biz* | Web: seo-diy.com
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:32 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0