언어/PHP, DB

file_get_contents_utf8() : file_get_contents()로 가져온 내용 UTF-8로 바꾸기

홍진표 2012. 11. 16. 17:58

다음 code snippet으로 웹에서 긁어온 내용을 UTF-8로 저장할 수 있다.
<?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));
}
?>