how to get utf 8 encoded file with php -
this question has answer here:
- utf-8 way through 14 answers
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
Post a Comment