Page 1 of 1

Cant able to read Latin alphabets in SCV

Posted: Sat May 22, 2010 5:26 am
by rajsekar2u
HI,

I cant able to read the Latin alphabets like " À Á Â Ã Ä Å È É Ê Ë à á â ã ä" from CSV. Its showing me junk characters.

The code which i used to read CSV is below:

Code: Select all

    if ( ! $file = file("CSV FILENAME", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) die ('Could not open input file');
	$match = "No";
	foreach($file as $line) 
	{ 
             print_r($file);
        }


Is there any way to read those characters?

Thanks in advance.

Re: Cant able to read Latin alphabets in SCV

Posted: Sat May 22, 2010 11:12 pm
by Chalks
instead of using file(), try using file_get_contents(). Read the comments on that page... you may find them helpful, especially this one:
A UTF-8 issue I've encountered is that of reading a URL with a non-UTF-8 encoding that is later displayed improperly since file_get_contents() related to it as UTF-8. This small function should show you how to address this issue:

Code: Select all

function file_get_contents_utf8($fn) {
     $content = file_get_contents($fn);
      return mb_convert_encoding($content, 'UTF-8',
          mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}
mb_convert_encoding() and mb_detect_encoding() will surely help you out.