note 85008 modified in function.file-get-contents by felipe
| From: | felipe@php.net | Date: | Mon, 11 Aug 2008 14:36:26 +0000 |
| Subject: | note 85008 modified in function.file-get-contents by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143366@lists.php.net to get a copy of this message | ||
A UTF-8 issue I've encountered is that of reading a URL with a non-UTF-8 encoding that is later
displayed improperly since file_get_contents() related to it as UTF-8. This small function should
show you how to address this issue:
<?php
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));
}
?>
--was--
A UTF-8 issue I've encountered is that of reading a URL with a non-UTF-8 encoding that is later
displayed improperly since file_get_contents() related to it as UTF-8. This small function should
show you how to address this issue:
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));
}
http://php.net/manual/en/function.file-get-contents.php