how to get utf 8 encoded file with php -


this question has answer here:

i want .html or .txt file folder php, file utf-8 encoded, , if use $html=file_get_contents('somewhere/somewhat.html'); , after echo $html; won't utf-8 encoded. see many "�" in text. idea? how can prevent this?

you need convert utf8 yourselves. use mb_convert_encoding() , 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


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -