PHPコード変換
3982 ワード
class Phpclass {
function __construct() {
}
/**
*
* @param string $fContents
* @param string $from
* @param string $to
* @return string
*/
public function auto_charset($fContents, $from='gbk', $to='utf-8')
{
$from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from;
$to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to;
if (strtoupper($from) === strtoupper($to) || empty($fContents) || (is_scalar($fContents) && !is_string($fContents))) {
//
return $fContents;
}
if (is_string($fContents)) {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($fContents, $to, $from);
} elseif (function_exists('iconv')) {
return iconv($from, $to, $fContents);
} else {
return $fContents;
}
}else {
return $fContents;
}
}//auto_charset
}