本文整理匯總了PHP中utf8::detect方法的典型用法代碼示例。如果您正苦於以下問題:PHP utf8::detect方法的具體用法?PHP utf8::detect怎麽用?PHP utf8::detect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utf8
的用法示例。
在下文中一共展示了utf8::detect方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: convert
/**
* Convert a foreign charset encoding from or to UTF-8
*/
function convert($string, $encoding = NULL, $destination = 'UTF-8')
{
if (!$encoding) {
$encoding = utf8::detect($string);
}
if ($encoding == $destination) {
return $string;
}
if (!empty($this->mb_sets)) {
$encode_mb = array_key_exists($encoding, $this->mb_sets);
$dest_mb = array_key_exists($destination, $this->mb_sets);
if ($encode_mb && $dest_mb) {
@mb_substitute_character('none');
return mb_convert_encoding($string, $destination, $encoding);
}
} else {
$encode_mb = $dest_mb = false;
}
$encode_iconv = array_key_exists($encoding, $this->iconv_sets);
$dest_iconv = array_key_exists($destination, $this->iconv_sets);
if ($encode_iconv && $dest_iconv) {
return @iconv($encoding, $destination . '//IGNORE', $string);
}
// must use mixed conversion
@mb_substitute_character('none');
if ($encode_mb) {
$instring = mb_convert_encoding($string, 'UTF-8', $encoding);
} else {
if ($encode_iconv) {
$instring = @iconv($encoding, 'UTF-8' . '//IGNORE', $string);
} else {
$instring = $string;
}
}
if ($dest_mb) {
$outstring = mb_convert_encoding($string, $destination, 'UTF-8');
} else {
if ($dest_iconv) {
$outstring = @iconv('UTF-8', $destination . '//IGNORE', $string);
} else {
$outstring = $string;
}
}
return $outstring;
}