在PHP中显示朝鲜语时出错

Hi all I need your help for my problem.

I try to display text (Korean) from a .txt file but the output is different. I have a .txt file contains Korean characters like this 냐는 한국을 사랑

but when i try :

$str= file_get_contents($path."result.txt");
echo $str;

on the browser the result came out like this : �먮뒗 �쒓뎅�� �щ옉

but It's OK when i just echo "냐는 한국을 사랑"

IS there something wrong ?

Thank for your help

Either use header("Content-Type: text/html; charset=UTF-8") in your php file or a meta tag in your html <meta charset='utf-8'>. And make sure the font you are using supports unicode characters you need.

Apparently the character encoding of the file is different from the character encoding of the HTML document that your code is generating.

You could dynamically convert the text data in PHP, or you could just use a suitable conversion program to convert the text file. You could just open the text file in a text editor and use Save As to save it as UTF-8 encoded (without BOM), assuming that your PHP is generating a UTF-8 encoded document.

I struggled a while fixing this problem until I discovered this which works perfectly for me:

echo call_user_func_array('mb_convert_encoding', array("행동 방식",'HTML-ENTITIES','UTF-8'));