本文整理汇总了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;
}