I want to get a .html or .txt file from a folder with PHP, but this file is UTF-8 encoded, and if I use $html=file_get_contents('somewhere/somewhat.html'); and after that I echo $html; then this won't be UTF-8 encoded. I see many "�" in the text. Any idea? How can I prevent this?
            Asked
            
        
        
            Active
            
        
            Viewed 983 times
        
    0
            
            
         
    
    
        Dylan Wheeler
        
- 6,928
- 14
- 56
- 80
 
    
    
        gabor aron
        
- 390
- 2
- 3
- 15
2 Answers
0
            
            
        Try to use iconv on your string: http://php.net/manual/pl/function.iconv.php
Other solution: http://php.net/manual/en/function.mb-convert-encoding.php
 
    
    
        user3161374
        
- 64
- 5
0
            You need to convert it to UTF8 yourselves. To do that use mb_convert_encoding() and mb_detect_encoding() PHP functions.
Like this,
$html=file_get_contents('somewhere/somewhat.html');
$html=mb_convert_encoding($html, 'UTF-8',mb_detect_encoding($html, 'UTF-8, ISO-8859-1', true));
echo $html;
mb_convert_encoding() converts character encoding
mb_detect_encoding() detects character encoding
 
    
    
        Alok Patel
        
- 7,842
- 5
- 31
- 47