<?php
 namespace TechOnline\Utils; class CharsetUtil { public static function toUtf8($content, $from = null) { if (empty($content)) { return $content; } if (null === $from) { $fileType = mb_detect_encoding($content, array('UTF-8', 'GBK', 'LATIN1', 'BIG5')); } else { $fileType = $from; } if (empty($from)) { return $content; } $fileType = strtoupper($from); if ($fileType == 'UTF-8') { return $content; } return mb_convert_encoding($content, 'UTF-8', $fileType); } }