file_get_contents() Breaks Up UTF-8 Characters file_get_contents() Breaks Up UTF-8 Characters php php

file_get_contents() Breaks Up UTF-8 Characters


I had similar problem with polish language

I tried:

$fileEndEnd = mb_convert_encoding($fileEndEnd, 'UTF-8', mb_detect_encoding($fileEndEnd, 'UTF-8', true));

I tried:

$fileEndEnd = utf8_encode ( $fileEndEnd );

I tried:

$fileEndEnd = iconv( "UTF-8", "UTF-8", $fileEndEnd );

And then -

$fileEndEnd = mb_convert_encoding($fileEndEnd, 'HTML-ENTITIES', "UTF-8");

This last worked perfectly !!!!!!


Solution suggested in the comments of the PHP manual entry for file_get_contents

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));}

You might also try your luck with http://php.net/manual/en/function.mb-internal-encoding.php


Alright. I have found out the file_get_contents() is not causing this problem. There's a different reason which I talk about in another question. Silly me.

See this question: Why Does DOM Change Encoding?